node/test/parallel/test-async-local-storage-snapshot.js
flakey5 9a82938b82 lib: add AsyncLocalStorage.bind() and .snapshot()
PR-URL: https://github.com/nodejs/node/pull/46387
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
2023-02-19 13:51:43 -08:00

17 lines
495 B
JavaScript

'use strict';
const common = require('../common');
const { strictEqual } = require('assert');
const { AsyncLocalStorage } = require('async_hooks');
const asyncLocalStorage = new AsyncLocalStorage();
const runInAsyncScope =
asyncLocalStorage.run(123, common.mustCall(() => AsyncLocalStorage.snapshot()));
const result =
asyncLocalStorage.run(321, common.mustCall(() => {
return runInAsyncScope(() => {
return asyncLocalStorage.getStore();
});
}));
strictEqual(result, 123);