Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

modern-async

nicolas-van148.3kMIT2.0.4TypeScript support: included

A modern tooling library for asynchronous operations using async/await, promises and async generators

async, await, promises, asynchronous, utility, util, async/await, queue, scheduler, generators

readme

modern-async Tweet

logo

Github-sponsors GitHub Repo stars Website Node.js CI npm Coverage Status JsDelivr

A modern JavaScript tooling library for asynchronous operations using async/await, promises and async generators.

This library is a modernized alternative to a lot of libraries like Async.js that were created using the legacy callback style to handle asynchronous operations. Its goal is to be as complete as any of those libraries while being built from the very beginning with async/await and promises in mind.

See the documentation.

  • Exclusively uses async/await, promises and async generators in its code, tests and documentation.
  • Has low bundle size.
  • Has 100% code coverage.
  • Bundled for ESM modules, CommonJS and UMD.
  • Works in node >= 8 and in the vast majority of browsers (very old browser compatibility can be achieved using Babel and shims).
  • Has Typescript support.

Stargazers repo roster for @nicolas-van/modern-async

Installation

npm install --save modern-async

Or use jsDelivr to get the UMD version. The content of the library will be available under the modernAsync global variable.

Usage

import { asyncMap, asyncSleep } from 'modern-async'

const array = [1, 2, 3]
const result = await asyncMap(array, async (v) => {
  await asyncSleep(10)
  return v * 2
})
console.log(result)

See the documentation for the rest.

Migrating from version 1.X to version 2.X

See the migration guide.

Changelog

The changelog.

Contribution Guide

The contribution guide

License

The license.

changelog

Changelog

2.0.2

2.0.1

2.0.0

  • Major re-design of the API. This re-design was made with the following goals:

    • Avoiding function naming conflict with popular libraries (notably lodash)
    • Simplifying the API by removing duplicate functions
    • Proposing safer default parameters regarding concurrency handling

    See the migration guide to know how to migrate to version 2.X.

  • Added reflectAsyncStatus() function.

1.1.4

  • Fixed typescript declarations.

1.1.3

  • Fixed Typescript definitions for reduce() and reduceRight().
  • Minor adjustments to the documentation.

1.1.1

  • Fixed issue where the typescript definition file was not exported to npm

1.1.0

  • Changed most of the functions that took Iterable as argument to make them also take an AsyncIterable.
  • Changed most of the functions that used a concurrency argument to allow them to take a Queue instead.
  • Added ordered argument to find, findIndex, findLimit and findIndexLimit.
  • Added new functions filterGenerator, mapGenerator, asyncIterableWrap, queueMicrotask, and toArray.
  • Fixed delay and delayCancellable inconsistencies due to setTimeout usage. Now they use corejs' setTimeout implementation.
  • Added Typescript declarations.

1.0.4

  • Fixed bug in forEachLimit

1.0.3

  • Performance improvements. Notably the Queue class will now avoid calling the delay() function and will immediately trigger any pending task as soon as a task is finished. This change indirectly impacts most functions in this library as they internally use Queue. This change can produce minor behavior changes but is not considered a breaking change.
  • Improved tests.

1.0.2

  • Altered UMD deployment to only support browsers that support async/await language feature. The reason is that bundling both regenerator-runtime and all the necessary shims is too complex. For older browsers it is easier to just process the lib with Babel then add regenerator-runtime and core-js.

1.0.1

  • Fixed map, filter and forEach behavior in case of exception. Pending tasks were not cancelled in case of exception and the behavior in that case was not documented as opposed to other functions.

1.0.1

First version.