mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 00:20:08 +01:00
PR-URL: https://github.com/nodejs/node/pull/60150 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
25 lines
726 B
JavaScript
25 lines
726 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const { AsyncLocalStorage } = require('async_hooks');
|
|
|
|
async function main() {
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
const err = new Error();
|
|
const next = () => Promise.resolve()
|
|
.then(() => {
|
|
assert.strictEqual(asyncLocalStorage.getStore().get('a'), 1);
|
|
throw err;
|
|
});
|
|
await assert.rejects(new Promise((resolve, reject) => {
|
|
asyncLocalStorage.run(new Map(), () => {
|
|
const store = asyncLocalStorage.getStore();
|
|
store.set('a', 1);
|
|
next().then(resolve, reject);
|
|
});
|
|
}), err);
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|
|
}
|
|
|
|
main().then(common.mustCall());
|