| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e89ec46 commit 6502489
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -253,6 +253,7 @@ const storageHook = createHook({ | |||
| 253 | 253 | } | |
| 254 | 254 | }); | |
| 255 | 255 | ||
| 256 | + const defaultAlsResourceOpts = { requireManualDestroy: true }; | ||
| 256 | 257 | class AsyncLocalStorage { | |
| 257 | 258 | constructor() { | |
| 258 | 259 | this.kResourceStore = Symbol('kResourceStore'); | |
@@ -293,8 +294,11 @@ class AsyncLocalStorage { | |||
| 293 | 294 | if (ObjectIs(store, this.getStore())) { | |
| 294 | 295 | return callback(...args); | |
| 295 | 296 | } | |
| 296 | - const resource = new AsyncResource('AsyncLocalStorage'); | ||
| 297 | - return resource.runInAsyncScope(() => { | ||
| 297 | + const resource = new AsyncResource('AsyncLocalStorage', | ||
| 298 | + defaultAlsResourceOpts); | ||
| 299 | + // Calling emitDestroy before runInAsyncScope avoids a try/finally | ||
| 300 | + // It is ok because emitDestroy only schedules calling the hook | ||
| 301 | + return resource.emitDestroy().runInAsyncScope(() => { | ||
| 298 | 302 | this.enterWith(store); | |
| 299 | 303 | return callback(...args); | |
| 300 | 304 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments