4 ms·
The example was intended specifically for when you want to do some IO in the initialisation of a class. However, by having a callback interface the caller does
by glenjamin 15y ago
The example was intended specifically for when you want to do some IO in the initialisation of a class.
However, by having a callback interface the caller doesn't need to know whether a particular call involves IO or not - and you're also free to introduce IO if needed.
A useful example would be using some sort of 2 level caching, where some stuff is in memory, and other things are in a persistant store out-of-process.
Also, consider the following as an example of a use-case for a callback/async aware map function
async.map(list_of_ids, fetchURLFromAPI, function(err, urls) {
request.respond(urls.join(","));
})