Last active
August 29, 2015 14:05
-
-
Save theRemix/75d41e12fbb7db585cd2 to your computer and use it in GitHub Desktop.
Haxe callback vs. promises
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
| Page.all(function(err:NodeErr, records:Array<Page>){ | |
| if(err != null) throw err; | |
| for(page in pages){ | |
| trace(page); | |
| } | |
| }) |
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
| // Long | |
| var pages = new Deferred<Array<Page>>(); | |
| var prom = pages.promise(); | |
| prom.then(function(val:Array<Page>){ | |
| for(page in pages){ | |
| trace(page); | |
| } | |
| }); | |
| prom.catchError(function(err){ | |
| throw err; | |
| }); | |
| pages.resolve(Page.all()); | |
| // Short | |
| var pages = new Deferred<Array<Page>>(); | |
| pages | |
| .promise() | |
| .then(function(val:Array<Page>){ | |
| for(page in pages){ | |
| trace(page); | |
| } | |
| }) | |
| .catchError(function(err){ | |
| throw err; | |
| }); | |
| pages.resolve(Page.all()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment