3 ms·
-pseudo code- function wait.for ( asyncFn, params ) { //call the async fn, returns immediately asyncFn(params, function(err,data){ //
by lucio 13y ago
-pseudo code-
function wait.for ( asyncFn, params ) {
//call the async fn, returns immediately
asyncFn(params, function(err,data){
//here the data is ready
thisFiber.err = err;
thisFiber.data = data;
thisFiber.resume(); //resume execution (after yield())
});
//we're in a fiber, so we can yield() to node's event loop
thisFiber.yield(); //pause here, give back control to node's event loop
// the next line will be executed when thisFiber.resume() is called
if (thisFiber.err) throw thisFiber.err; // throw into the caller of wait.for
return thisFiber.data; //ok
}