| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e00c1ec commit 0ec912f
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,9 @@ const { | |||
| 43 | 43 | willEmitClose: _willEmitClose, | |
| 44 | 44 | kIsClosedPromise, | |
| 45 | 45 | } = require('internal/streams/utils'); | |
| 46 | + | ||
| 47 | + // Lazy load | ||
| 48 | + let AsyncLocalStorage; | ||
| 46 | 49 | let addAbortListener; | |
| 47 | 50 | ||
| 48 | 51 | function isRequest(stream) { | |
@@ -63,7 +66,8 @@ function eos(stream, options, callback) { | |||
| 63 | 66 | validateFunction(callback, 'callback'); | |
| 64 | 67 | validateAbortSignal(options.signal, 'options.signal'); | |
| 65 | 68 | ||
| 66 | - callback = once(callback); | ||
| 69 | + AsyncLocalStorage ??= require('async_hooks').AsyncLocalStorage; | ||
| 70 | + callback = once(AsyncLocalStorage.bind(callback)); | ||
| 67 | 71 | ||
| 68 | 72 | if (isReadableStream(stream) || isWritableStream(stream)) { | |
| 69 | 73 | return eosWeb(stream, options, callback); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,20 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + | ||
| 3 | + const common = require('../common'); | ||
| 4 | + const { Readable, finished } = require('stream'); | ||
| 5 | + const { AsyncLocalStorage } = require('async_hooks'); | ||
| 6 | + const { strictEqual } = require('assert'); | ||
| 7 | + | ||
| 8 | + // This test verifies that AsyncLocalStorage context is maintained | ||
| 9 | + // when using stream.finished() | ||
| 10 | + | ||
| 11 | + const readable = new Readable(); | ||
| 12 | + const als = new AsyncLocalStorage(); | ||
| 13 | + | ||
| 14 | + als.run(321, () => { | ||
| 15 | + finished(readable, common.mustCall(() => { | ||
| 16 | + strictEqual(als.getStore(), 321); | ||
| 17 | + })); | ||
| 18 | + }); | ||
| 19 | + | ||
| 20 | + readable.destroy(); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments