Skip to content

Commit

Permalink
fix(node): reuseExisting does not need to call bind on domain (#7780)
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish authored Apr 7, 2023
1 parent 715876b commit f4e92ca
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/node/src/async/domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,22 @@ function getCurrentHub(): Hub | undefined {
}

function runWithAsyncContext<T>(callback: (hub: Hub) => T, options: RunWithAsyncContextOptions): T {
const local = options?.reuseExisting ? getActiveDomain<domain.Domain>() || domain.create() : domain.create();
if (options?.reuseExisting) {
const activeDomain = getActiveDomain<domain.Domain & Carrier>();

if (activeDomain) {
for (const emitter of options.args || []) {
if (emitter instanceof EventEmitter) {
activeDomain.add(emitter);
}
}

// We're already in a domain, so we don't need to create a new one, just call the callback with the current hub
return callback(getHubFromCarrier(activeDomain));
}
}

const local = domain.create();

for (const emitter of options.args || []) {
if (emitter instanceof EventEmitter) {
Expand Down

0 comments on commit f4e92ca

Please sign in to comment.