File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -27,7 +27,22 @@ function getCurrentHub(): Hub | undefined {
2727}
2828
2929function runWithAsyncContext < T > ( callback : ( hub : Hub ) => T , options : RunWithAsyncContextOptions ) : T {
30- const local = options ?. reuseExisting ? getActiveDomain < domain . Domain > ( ) || domain . create ( ) : domain . create ( ) ;
30+ if ( options ?. reuseExisting ) {
31+ const activeDomain = getActiveDomain < domain . Domain & Carrier > ( ) ;
32+
33+ if ( activeDomain ) {
34+ for ( const emitter of options . args || [ ] ) {
35+ if ( emitter instanceof EventEmitter ) {
36+ activeDomain . add ( emitter ) ;
37+ }
38+ }
39+
40+ // We're already in a domain, so we don't need to create a new one, just call the callback with the current hub
41+ return callback ( getHubFromCarrier ( activeDomain ) ) ;
42+ }
43+ }
44+
45+ const local = domain . create ( ) ;
3146
3247 for ( const emitter of options . args || [ ] ) {
3348 if ( emitter instanceof EventEmitter ) {
You can’t perform that action at this time.
0 commit comments