2019-03-02 04:31:36 +08:00
|
|
|
'use strict';
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { AsyncLocalStorage } = require('async_hooks');
|
|
|
|
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
2020-03-04 19:57:56 +08:00
|
|
|
const outer = {};
|
|
|
|
const inner = {};
|
2019-03-02 04:31:36 +08:00
|
|
|
|
2020-03-04 19:57:56 +08:00
|
|
|
function testInner() {
|
|
|
|
assert.strictEqual(asyncLocalStorage.getStore(), outer);
|
|
|
|
|
|
|
|
asyncLocalStorage.run(inner, () => {
|
|
|
|
assert.strictEqual(asyncLocalStorage.getStore(), inner);
|
|
|
|
});
|
|
|
|
assert.strictEqual(asyncLocalStorage.getStore(), outer);
|
|
|
|
|
|
|
|
asyncLocalStorage.exit(() => {
|
|
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|
|
|
|
});
|
|
|
|
assert.strictEqual(asyncLocalStorage.getStore(), outer);
|
|
|
|
}
|
|
|
|
|
|
|
|
asyncLocalStorage.run(outer, testInner);
|
|
|
|
assert.strictEqual(asyncLocalStorage.getStore(), undefined);
|