0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/async-hooks/test-async-local-storage-http.js

22 lines
617 B
JavaScript
Raw Normal View History

'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, () => {
asyncLocalStorage.run(new Map(), () => {
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();
});
});
});