Created
November 21, 2017 21:48
-
-
Save moiz-frost/b4c4df2fb470b9b8b78a469b7342a0c5 to your computer and use it in GitHub Desktop.
Async await
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
| var async = require('async'); | |
| var parallel = require('async/parallel'); | |
| function giveData() { | |
| var data; | |
| async.parallel([ | |
| function(callback){ | |
| callback(null, 'one'); | |
| }, | |
| function(callback){ | |
| callback(null, 'two'); | |
| } | |
| ], | |
| function(err, results){ | |
| // the results array will equal ['one','two'] even though | |
| // the second function had a shorter timeout. | |
| if (err) { | |
| console.log(err); | |
| } else { | |
| // console.log(results); | |
| // return results; | |
| data = results; | |
| } | |
| }); | |
| return data; | |
| } | |
| console.log(giveData()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment