waitfor.js
function(err,data){
                            if (fiber.callbackAlreadyCalled)
                                 throw new Error("Callback for function "+fnName+" called twice. Wait.for already resumed the execution.");
                            fiber.callbackAlreadyCalled = true;
                            fiber.err=err; //store err on fiber object
                            fiber.data=data; //store data on fiber object
                            if (!fiber.yielded) {//when callback is called *before* async function returns
                                // no need to "resume" because we never got the chance to "yield"
                                return;
                            }
                            else {
                                //resume fiber after "yield"
                                fiber.run();   
                            }
                        }
function(err,data){
                            if (fiber.callbackAlreadyCalled)
                                 throw new Error("Callback for function "+fnName+" called twice. Wait.for already resumed the execution.");
                            fiber.callbackAlreadyCalled = true;
                            fiber.err=err; //store err on fiber object
                            fiber.data=data; //store data on fiber object
                            if (!fiber.yielded) {//when callback is called *before* async function returns
                                // no need to "resume" because we never got the chance to "yield"
                                return;
                            }
                            else {
                                //resume fiber after "yield"
                                fiber.run();   
                            }
                        }
function ( err , data ) { if ( fiber . callbackAlreadyCalled ) throw new Error ( "Callback for function " + fnName + " called twice. Wait.for already resumed the execution." ) ; fiber . callbackAlreadyCalled = true ; fiber . err = err ; //store err on fiber object fiber . data = data ; //store data on fiber object if ( ! fiber . yielded ) { //when callback is called *before* async function returns // no need to "resume" because we never got the chance to "yield" return ; } else { //resume fiber after "yield" fiber . run ( ) ; } }
create a closure to resume on callback
create a closure to resume on callback