Skip to content

async_hooks: introduce mandatory store argument in AsyncLocalStorage run methods

This PR introduces store as the first argument in AsyncLocalStorage's .run*() methods. The change is motivated by the following expectation: most users are going to use a custom object as the store and an extra Map created by the old implementation is an overhead for their use case.

Important note. This is a backwards incompatible change. But as AsyncLocalStorage API has just landed into master (https://github.com/nodejs/node/commit/9c702922cdcf830cedb92d51e5dc9f956584c3ee), it should be OK.

This PR implements the most simple (and as I believe, the most convenient for users) option from this discussion thread: https://github.com/nodejs/node/pull/26540#discussion_r382896437

cc @vdeturckheim, @Qard, @Flarna

API change

Both run methods now have .run*(store, callback[, ..args]) signature instead of the old .run*(callback[, ..args]). For users who want to use a Map this change simply means

asyncLocalStorage.run(new Map(), () => /* ... */)

call instead of

asyncLocalStorage.run(() => /* ... */)
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Merge request reports

Loading