Last active
August 29, 2015 13:59
-
-
Save nomadster/10990033 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// file: UnController.js | |
/** | |
* Un controller è già di per se un generator. Quindi qui non cambia molto. | |
*/ | |
module.exports = function* (param1, $context, $view, serv){ | |
//Qua possiamo usare le generator delegation | |
var result = yield* serv.method(42); | |
} | |
//file: serv.js | |
/** | |
* La novità principale è qui. I metodi del tuo servizio diventano generator e possono | |
* fare yield a loro volta! | |
*/ | |
function foo(){ | |
return function(callback){ | |
callback(null,42); //Torna 42 | |
callback(roba); //Roba è errore | |
} | |
} | |
module.exports = function UnServizio(servizioCheTiServe){ | |
this.method = function*(param){ | |
//yield di un Thunk | |
var res = yield servizioCheTiServe.chiamalo();//Questo deve essere il solito Thunk | |
var altrores = yield* servizioCheTiServe.unAltroNome(); //Lui è un generator | |
return yield foo(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment