mirror of
https://github.com/nodejs/node.git
synced 2024-11-24 20:29:23 +01:00
fe751df537
PR-URL: https://github.com/nodejs/node/pull/44943 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Bryan English <bryan@bryanenglish.com>
30 lines
846 B
JavaScript
30 lines
846 B
JavaScript
'use strict';
|
|
|
|
const common = require('../common');
|
|
const { AsyncLocalStorage } = require('async_hooks');
|
|
const dc = require('diagnostics_channel');
|
|
const assert = require('assert');
|
|
|
|
const channel = dc.tracingChannel('test');
|
|
const store = new AsyncLocalStorage();
|
|
|
|
const firstContext = { foo: 'bar' };
|
|
const secondContext = { baz: 'buz' };
|
|
|
|
channel.start.bindStore(store, common.mustCall(() => {
|
|
return firstContext;
|
|
}));
|
|
|
|
channel.asyncStart.bindStore(store, common.mustCall(() => {
|
|
return secondContext;
|
|
}));
|
|
|
|
assert.strictEqual(store.getStore(), undefined);
|
|
channel.traceCallback(common.mustCall((cb) => {
|
|
assert.deepStrictEqual(store.getStore(), firstContext);
|
|
setImmediate(cb);
|
|
}), 0, {}, null, common.mustCall(() => {
|
|
assert.deepStrictEqual(store.getStore(), secondContext);
|
|
}));
|
|
assert.strictEqual(store.getStore(), undefined);
|