( ...rest: [callback: (scope: Scope) => T] | [scope: Scope | undefined, callback: (scope: Scope) => T] )
| 71 | * Either creates a new active scope, or sets the given scope as active scope in the given callback. |
| 72 | */ |
| 73 | export function withScope<T>( |
| 74 | ...rest: [callback: (scope: Scope) => T] | [scope: Scope | undefined, callback: (scope: Scope) => T] |
| 75 | ): T { |
| 76 | const carrier = getMainCarrier(); |
| 77 | const acs = getAsyncContextStrategy(carrier); |
| 78 | |
| 79 | // If a scope is defined, we want to make this the active scope instead of the default one |
| 80 | if (rest.length === 2) { |
| 81 | const [scope, callback] = rest; |
| 82 | |
| 83 | if (!scope) { |
| 84 | return acs.withScope(callback); |
| 85 | } |
| 86 | |
| 87 | return acs.withSetScope(scope, callback); |
| 88 | } |
| 89 | |
| 90 | return acs.withScope(rest[0]); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Attempts to fork the current isolation scope and the current scope based on the current async context strategy. If no |
no test coverage detected