Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Rename remove() method to destroy()
  • Loading branch information
puzpuzpuz committed Feb 13, 2020
commit b65d09a4d67ef063de4b97013ef0da2c89793ab2
2 changes: 1 addition & 1 deletion benchmark/async_hooks/async-resource-vs-destroy.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function buildAsyncLocal(getServe) {
}

function close() {
asyncLocal.remove();
asyncLocal.destroy();
server.close();
}
}
Expand Down
8 changes: 4 additions & 4 deletions doc/api/async_hooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ Creates a new instance of `AsyncLocal`.
* Returns: {any}

Returns the value of the `AsyncLocal` in current execution context,
or `undefined` if the value is not set or the `AsyncLocal` was removed.
or `undefined` if the value is not set or the `AsyncLocal` was destroyed.

### `asyncLocal.set(value)`

Expand Down Expand Up @@ -681,13 +681,13 @@ setImmediate(() => {
});
```

If the `AsyncLocal` was removed before this call is made,
If the `AsyncLocal` was destroyed before this call is made,
the call will have no effect.

### `asyncLocal.remove()`
### `asyncLocal.destroy()`

Disables value propagation for the `AsyncLocal` and releases all
values stored by it. Calling `asyncLocal.remove()` multiple times will
values stored by it. Calling `asyncLocal.destroy()` multiple times will
have no effect.

Any subsequent `asyncLocal.get()` calls will return `undefined`.
Expand Down
2 changes: 1 addition & 1 deletion lib/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class AsyncLocal {
}
}

remove() {
destroy() {
const index = locals.indexOf(this);
if (index === -1)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { AsyncLocal } = async_hooks;

// This test ensures correct work of the global hook
// that serves for propagation of all `AsyncLocal`s
// in the context of `.remove()` call
// in the context of `.destroy()` call

const asyncLocalOne = new AsyncLocal();
asyncLocalOne.set(1);
Expand All @@ -16,12 +16,12 @@ asyncLocalTwo.set(2);

setImmediate(() => {
// Removal of one local should not affect others
asyncLocalTwo.remove();
asyncLocalTwo.destroy();
assert.strictEqual(asyncLocalOne.get(), 1);

// Removal of the last active local should not
// prevent propagation of locals created later
asyncLocalOne.remove();
asyncLocalOne.destroy();
const asyncLocalThree = new AsyncLocal();
asyncLocalThree.set(3);
setImmediate(() => {
Expand Down
6 changes: 3 additions & 3 deletions test/async-hooks/test-async-local.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ const obj = {};
asyncLocal.set(obj);
assert.strictEqual(asyncLocal.get(), obj);

asyncLocal.remove();
asyncLocal.destroy();
assert.strictEqual(asyncLocal.get(), undefined);

// Subsequent .set() is ignored
asyncLocal.set('bar');
assert.strictEqual(asyncLocal.get(), undefined);

// Subsequent .remove() does not throw
asyncLocal.remove();
// Subsequent .destroy() does not throw
asyncLocal.destroy();