2020-02-25 22:12:51 +08:00
|
|
|
'use strict';
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const {
|
|
|
|
AsyncLocalStorage,
|
|
|
|
executionAsyncResource
|
|
|
|
} = require('async_hooks');
|
|
|
|
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
|
|
|
|
|
|
const outerResource = executionAsyncResource();
|
|
|
|
|
2020-08-04 05:19:54 +08:00
|
|
|
const store = new Map();
|
|
|
|
asyncLocalStorage.run(store, () => {
|
|
|
|
assert.strictEqual(asyncLocalStorage.getStore(), store);
|
|
|
|
const innerResource = executionAsyncResource();
|
|
|
|
assert.notStrictEqual(innerResource, outerResource);
|
|
|
|
asyncLocalStorage.run(store, () => {
|
|
|
|
assert.strictEqual(asyncLocalStorage.getStore(), store);
|
|
|
|
assert.strictEqual(executionAsyncResource(), innerResource);
|
|
|
|
const otherStore = new Map();
|
|
|
|
asyncLocalStorage.run(otherStore, () => {
|
|
|
|
assert.strictEqual(asyncLocalStorage.getStore(), otherStore);
|
|
|
|
assert.notStrictEqual(executionAsyncResource(), innerResource);
|
|
|
|
assert.notStrictEqual(executionAsyncResource(), outerResource);
|
|
|
|
});
|
|
|
|
});
|
2020-02-25 22:12:51 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
assert.strictEqual(executionAsyncResource(), outerResource);
|