Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 10 additions & 5 deletions lib/async_hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const {
executionAsyncId,
triggerAsyncId,
// Private API
hasAsyncIdStack,
getHookArrays,
enableHooks,
disableHooks,
Expand Down Expand Up @@ -179,12 +180,16 @@ class AsyncResource {
const asyncId = this[async_id_symbol];
emitBefore(asyncId, this[trigger_async_id_symbol], this);

const ret = thisArg === undefined ?
fn(...args) :
ReflectApply(fn, thisArg, args);
try {
const ret = thisArg === undefined ?
fn(...args) :
ReflectApply(fn, thisArg, args);

emitAfter(asyncId);
return ret;
return ret;
} finally {
if (hasAsyncIdStack())
emitAfter(asyncId);
}
}

emitDestroy() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

require('../common');
const { AsyncResource } = require('async_hooks');

try {
new AsyncResource('foo').runInAsyncScope(() => { throw new Error('bar'); });
} catch {}
// Should abort (fail the case) if async id is not matching.

This file was deleted.