Vote count:
0
I'm trying to build a scraper using Node.js where I need some help implementing the callback pattern properly.
I'm having trouble implementing it the right what. What I am looking to do is something like this
var client = function(){};
client.prototype.init = function() {
// do something
this.A();
}
client.prototype.A = function(callback) {
// do something
// run callback
if(recursive_condition_fulfilled)
myclient.A(callback)
}
var myClient = new client();
var myCallback = function(callback){
// do something
}
myClient.init(myCallback)
The problem arises when I have an async function B() which runs inside A()
client.prototype.A = function(callback) {
// do something
this.B();
// wait for B
// once B is done
// run callback()
// then run the following
if(recursive_condition_fulfilled)
myclient.A(callback)
}
client.prototype.B = function(callback) {
// do something
// run callback
if(recursive_condition_fulfilled)
myclient.A(callback)
}
How do I implement the later promises part? where it says
// wait for B
// once B is done
// run callback()
asked 29 secs ago
How do I implement a nested callback pattern peroperly in Javascript
Aucun commentaire:
Enregistrer un commentaire