mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
async_hooks: introduce async-context API
Adding AsyncLocalStorage class to async_hooks module. This API provide a simple CLS-like set of features. Co-authored-by: Andrey Pechkurov <apechkurov@gmail.com> PR-URL: https://github.com/nodejs/node/pull/26540 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
72b6cea25d
commit
9c702922cd
13 changed files with 667 additions and 3 deletions
20
test/async-hooks/test-async-local-storage-args.js
Normal file
20
test/async-hooks/test-async-local-storage-args.js
Normal file
|
@ -0,0 +1,20 @@
|
|||
'use strict';
|
||||
require('../common');
|
||||
const assert = require('assert');
|
||||
const { AsyncLocalStorage } = require('async_hooks');
|
||||
|
||||
const asyncLocalStorage = new AsyncLocalStorage();
|
||||
|
||||
asyncLocalStorage.run((runArg) => {
|
||||
assert.strictEqual(runArg, 1);
|
||||
asyncLocalStorage.exit((exitArg) => {
|
||||
assert.strictEqual(exitArg, 2);
|
||||
}, 2);
|
||||
}, 1);
|
||||
|
||||
asyncLocalStorage.runSyncAndReturn((runArg) => {
|
||||
assert.strictEqual(runArg, 'foo');
|
||||
asyncLocalStorage.exitSyncAndReturn((exitArg) => {
|
||||
assert.strictEqual(exitArg, 'bar');
|
||||
}, 'bar');
|
||||
}, 'foo');
|
Loading…
Add table
Add a link
Reference in a new issue