xref: /third_party/node/test/async-hooks/test-async-local-storage-http.js
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/async-hooks/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_cirequire('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { AsyncLocalStorage } = require('async_hooks');
51cb0ef41Sopenharmony_ciconst http = require('http');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciconst asyncLocalStorage = new AsyncLocalStorage();
81cb0ef41Sopenharmony_ciconst server = http.createServer((req, res) => {
91cb0ef41Sopenharmony_ci  res.end('ok');
101cb0ef41Sopenharmony_ci});
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_ciserver.listen(0, () => {
131cb0ef41Sopenharmony_ci  asyncLocalStorage.run(new Map(), () => {
141cb0ef41Sopenharmony_ci    const store = asyncLocalStorage.getStore();
151cb0ef41Sopenharmony_ci    store.set('hello', 'world');
161cb0ef41Sopenharmony_ci    http.get({ host: 'localhost', port: server.address().port }, () => {
171cb0ef41Sopenharmony_ci      assert.strictEqual(asyncLocalStorage.getStore().get('hello'), 'world');
181cb0ef41Sopenharmony_ci      server.close();
191cb0ef41Sopenharmony_ci    });
201cb0ef41Sopenharmony_ci  });
211cb0ef41Sopenharmony_ci});
22

Indexes created Thu Nov 07 10:32:03 CST 2024