2019-03-01 21:31:36 +01:00
|
|
|
'use strict';
|
|
|
|
require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const { AsyncLocalStorage } = require('async_hooks');
|
|
|
|
const http = require('http');
|
|
|
|
|
|
|
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
|
|
const server = http.createServer((req, res) => {
|
|
|
|
res.end('ok');
|
|
|
|
});
|
|
|
|
|
|
|
|
server.listen(0, () => {
|
2020-02-24 11:00:59 +01:00
|
|
|
asyncLocalStorage.run(new Map(), () => {
|
2019-03-01 21:31:36 +01:00
|
|
|
const store = asyncLocalStorage.getStore();
|
|
|
|
store.set('hello', 'world');
|
|
|
|
http.get({ host: 'localhost', port: server.address().port }, () => {
|
|
|
|
assert.strictEqual(asyncLocalStorage.getStore().get('hello'), 'world');
|
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|