Releases: caolan/async
v2.3.0
- Added support for ES2017
asyncfunctions. Wherever you can pass a Node-style/CPS function that uses a callback, you can also pass anasyncfunction. Previously, you had to wrapasyncfunctions withasyncify. The caveat is that it will only work ifasyncfunctions are supported natively in your environment, transpiled implementations can't be detected. (#1386, #1390)
v2.2.0
v2.1.5
v2.1.3
v2.1.2
v2.1.0
v2.0.0
Lots of changes here!
First and foremost, we have a slick new site for docs. Special thanks to @hargasinski for his work converting our old docs to jsdoc format and implementing the new website. Also huge ups to @ivanseidel for designing our new logo. It was a long process for both of these tasks, but I think these changes turned out extraordinary well.
The biggest feature is modularization. You can now require("async/series") to only require the series function. Every Async library function is available this way. You still can require("async") to require the entire library, like you could do before.
We also provide Async as a collection of ES2015 modules. You can now import {each} from 'async-es' or import waterfall from 'async-es/waterfall'. If you are using only a few Async functions, and are using a ES bundler such as Rollup, this can significantly lower your build size.
Major thanks to @Kikobeats, @aearly and @megawac for doing the majority of the modularization work, as well as @jdalton and @Rich-Harris for advisory work on the general modularization strategy.
Another one of the general themes of the 2.0 release is standardization of what an "async" function is. We are now more strictly following the node-style continuation passing style. That is, an async function is a function that:
- Takes a variable number of arguments
- The last argument is always a callback
- The callback can accept any number of arguments
- The first argument passed to the callback will be treated as an error result, if the argument is truthy
- Any number of result arguments can be passed after the "error" argument
- The callback is called once and exactly once, either on the same tick or later tick of the JavaScript event loop.
There were several cases where Async accepted some functions that did not strictly have these properties, most notably auto, every, some, and filter.
Another theme is performance. We have eliminated internal deferrals in all cases where they make sense. For example, in waterfall and auto, there was a setImmediate between each task -- these deferrals have been removed. A setImmediate call can add up to 1ms of delay. This might not seem like a lot, but it can add up if you are using many Async functions in the course of processing a HTTP request, for example. Nearly all asynchronous functions that do I/O already have some sort of deferral built in, so the extra deferral is unnecessary. The trade-off of this change is removing our built-in stack-overflow defense. Many synchronous callback calls in series can quickly overflow the JS call stack. If you do have a function that is sometimes synchronous (calling its callback on the same tick), and are running into stack overflows, wrap it with async.ensureAsync().
Another big performance win has been re-implementing queue, cargo, and priorityQueue with doubly linked lists instead of arrays. This has lead to queues being an order of magnitude faster on large sets of tasks.
New Features
- Async is now modularized. Individual functions can be
require()d from the main package. (require('async/auto')) (#984, #996) - Async is also available as a collection of ES2015 modules in the new
async-espackage. (import {forEachSeries} from 'async-es') (#984, #996) - Added
race, analogous toPromise.race(). It will run an array of async tasks in parallel and will call its callback with the result of the first task to respond. (#568, #1038) - Collection methods now accept ES2015 iterators. Maps, Sets, and anything that implements the iterator spec can now be passed directly to
each,map,parallel, etc.. (#579, #839, #1074) - Added
mapValues, for mapping over the properties of an object and returning an object with the same keys. (#1157, #1177) - Added
timeout, a wrapper for an async function that will make the task time-out after the specified time. (#1007, #1027) - Added
reflectandreflectAll, analagous toPromise.reflect(), a wrapper for async tasks that always succeeds, by gathering results and errors into an object. (#942, #1012, #1095) constantsupports dynamic arguments -- it will now always use its last argument as the callback. (#1016, #1052)setImmediateandnextTicknow support arguments to partially apply to the deferred function, like the node-native versions do. (#940, #1053)autonow supports resolving cyclic dependencies using Kahn's algorithm (#1140).- Added
autoInject, a relative ofautothat automatically spreads a task's dependencies as arguments to the task function. (#608, #1055, #1099, #1100) - You can now limit the concurrency of
autotasks. (#635, #637) - Added
retryable, a relative ofretrythat wraps an async function, making it retry when called. (#1058) retrynow supports specifying a function that determines the next time interval, useful for exponential backoff, logging and other retry strategies. (#1161)retrywill now pass all of the arguments the task function was resolved with to the callback (#1231).- Added
q.unsaturated-- callback called when aqueue's number of running workers falls below a threshold. (#868, #1030, #1033, #1034) - Added
q.error-- a callback called whenever aqueuetask calls its callback with an error. (#1170) applyEachandapplyEachSeriesnow pass results to the final callback. (#1088)
Breaking changes
- Calling a callback more than once is considered an error, and an error will be thrown. This had an explicit breaking change in
waterfall. If you were relying on this behavior, you should more accurately represent your control flow as an event emitter or stream. (#814, #815, #1048, #1050) autotask functions now always take the callback as the last argument. If a task has dependencies, theresultsobject will be passed as the first argument. To migrate old task functions, wrap them with_.flip(#1036, #1042)- Internal
setImmediatecalls have been refactored away. This may make existing flows vulnerable to stack overflows if you use many synchronous functions in series. UseensureAsyncto work around this. (#696, #704, #1049, #1050) mapused to return an object when iterating over an object.mapnow always returns an array, like in other libraries. The previous object behavior has been split out intomapValues. (#1157, #1177)filter,reject,some,every, and related functions now expect an error as the first callback argument, rather than just a simple boolean. Passnullas the first argument, or usefs.accessinstead offs.exists. (#118, #774, #1028, #1041){METHOD}and{METHOD}Seriesare now implemented in terms of{METHOD}Limit. This is a major internal simplification, and is not expected to cause many problems, but it does subtly affect how functions execute internally. (#778, #847)retry's callback is now optional. Previousl...