Created
June 5, 2017 15:22
-
-
Save bluepnume/06769bbb783bbb71e68f255e125d83ee 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
// Here's a mock ajax function | |
function ajax(url, callback) { | |
setTimeout(function() { | |
if (Math.random() < 0.25) { | |
callback(new Error(`Something went wrong calling ${url}`)) | |
} else { | |
callback(null, { | |
url: url, | |
data: { | |
foo: 'bar' | |
} | |
}) | |
} | |
}, 1000); | |
} | |
// And here's how you call it: | |
ajax('/api/xxx', function(err, result) { | |
if (err) { | |
console.error('We got an error:', err); | |
} else { | |
console.info('We got a result:', result); | |
} | |
}); | |
// 1. Call /api/user/danny, /api/user/jilly, and /api/user/partario one after another, then console log each user after ALL the calls have completed | |
// 2. Call /api/user/danny, /api/user/jilly, and /api/user/partario in parallel, then console log each user after ALL the calls have completed | |
// 3. Use async.js to make the three calls in parallel | |
wildlingjill
commented
Jun 6, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment