Files
Xen-Orchestra-xen-orchestra…/@xen-orchestra/async-map
Bastien Nollet 9cdaf6bb41 feat: technical release (#10305)
* feat(@xen-orchestra/async-map): 0.1.4

* feat(xo-common): 0.11.0

* feat(xen-api): 4.9.0

* feat(@vates/types): 1.30.2

* feat(@xen-orchestra/acl): 1.6.0

* feat(@xen-orchestra/xapi): 8.10.3

* feat(@xen-orchestra/backups): 0.74.0

* feat(@xen-orchestra/backups-cli): 1.1.14

* feat(@xen-orchestra/disk-cli): 2.2.1

* feat(@xen-orchestra/immutable-backups): 3.0.5

* feat(@xen-orchestra/web-core): 0.59.0

* feat(@xen-orchestra/mixins): 0.20.2

* feat(@xen-orchestra/proxy): 0.31.7

* feat(@xen-orchestra/proxy-cli): 0.3.3

* feat(@xen-orchestra/qa-test): 1.2.0

* feat(@xen-orchestra/rest-api): 0.38.0

* feat(@xen-orchestra/upload-ova): 0.1.9

* feat(@xen-orchestra/web): 0.58.0

* feat(xo-acl-resolver): 0.5.4

* feat(xo-cli): 0.32.4

* feat(xo-server): 5.207.3

* feat(xo-server-audit): 0.15.2

* feat(xo-server-ipmi-sensors): 2.1.0

* feat(xo-server-netbox): 1.13.2

* feat(xo-server-sdn-controller): 1.4.1

* feat(xo-web): 5.202.0

* chore(CHANGELOG): update next
2026-08-25 16:19:35 +02:00
..
2022-02-18 17:11:52 +01:00
2026-08-25 16:19:35 +02:00
2023-02-06 11:25:12 +01:00

@xen-orchestra/async-map

Package Version License PackagePhobia Node compatibility

Promise.all + map for all iterables

Install

Installation of the npm package:

npm install --save @xen-orchestra/async-map

Usage

asyncMap(iterable, iteratee, thisArg = iterable)

Similar to Promise.all + Array#map for all iterables: calls iteratee for each item in iterable, and returns a promise of an array containing the awaited result of each calls to iteratee.

It rejects as soon as te first call to iteratee rejects.

import { asyncMap } from '@xen-orchestra/async-map'

const array = await asyncMap(iterable, iteratee, thisArg)

It can be used with any iterables (Array, Map, etc.):

const map = new Map()
map.set('foo', 42)
map.set('bar', 3.14)

const array = await asyncMap(map, async function ([key, value]) {
  // TODO: do async computation
  //
  // the map can be accessed via `this`
})

Use with plain objects

Plain objects are not iterable, but you can use Object.keys, Object.values or Object.entries to help:

const object = {
  foo: 42,
  bar: 3.14,
}

const array = await asyncMap(
  Object.entries(object),
  async function ([key, value]) {
    // TODO: do async computation
    //
    // the object can be accessed via `this` because it's been passed as third arg
  },
  object
)

asyncMapSettled(iterable, iteratee, thisArg = iterable)

Similar to asyncMap but waits for all promises to settle before rejecting.

import { asyncMapSettled } from '@xen-orchestra/async-map'

const array = await asyncMapSettled(iterable, iteratee, thisArg)

Contributions

Contributions are very welcomed, either on the documentation or on the code.

You may:

  • report any issue you've encountered;
  • fork and create a pull request.

License

ISC © Vates SAS