File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1853,6 +1853,24 @@ Emitted when [`child_process.spawn()`][] encounters an error.
18531853
18541854Emitted when [ ` process.execve() ` ] [ ] is invoked.
18551855
1856+ #### Streams
1857+
1858+ > Stability: 1 - Experimental
1859+
1860+ <!-- YAML
1861+ added: REPLACEME
1862+ -->
1863+
1864+ ##### Event: ` 'stream.web.done' `
1865+
1866+ * ` stream ` {ReadableStream} The stream that finished.
1867+
1868+ Emitted when a [ ` ReadableStream ` ] [ ] has finished, either because all data has
1869+ been read or because the stream was cancelled. The event fires once per stream,
1870+ after the stream has transitioned to the ` 'closed' ` state. It is emitted for
1871+ both the async iterator (` for await (...) ` ) and the direct reader
1872+ (` reader.read() ` , including BYOB readers) consumption paths.
1873+
18561874#### Web Locks
18571875
18581876> Stability: 1 - Experimental
@@ -1917,6 +1935,7 @@ Emitted when a new thread is created.
19171935[ TracingChannel Channels ] : #tracingchannel-channels
19181936[ `'uncaughtException'` ] : process.md#event-uncaughtexception
19191937[ `BoundedChannel` ] : #class-boundedchannel
1938+ [ `ReadableStream` ] : webstreams.md#class-readablestream
19201939[ `TracingChannel` ] : #class-tracingchannel
19211940[ `asyncEnd` event ] : #asyncendevent
19221941[ `asyncStart` event ] : #asyncstartevent
Original file line number Diff line number Diff line change @@ -43,3 +43,28 @@ import * as dc from 'diagnostics_channel';
4343
4444 channel . unsubscribe ( subscriber ) ;
4545}
46+
47+ {
48+ const readable = new ReadableStream ( {
49+ type : 'bytes' ,
50+ start ( controller ) {
51+ controller . enqueue ( new Uint8Array ( [ 1 , 2 , 3 ] ) ) ;
52+ controller . close ( ) ;
53+ } ,
54+ } ) ;
55+
56+ const channel = dc . channel ( 'stream.web.done' ) ;
57+ const subscriber = common . mustCall ( ( { stream } ) => {
58+ assert . strictEqual ( readable , stream ) ;
59+ assert . strictEqual ( readable [ util . kState ] . state , 'closed' ) ;
60+ } ) ;
61+ channel . subscribe ( subscriber ) ;
62+
63+ const reader = readable . getReader ( { mode : 'byob' } ) ;
64+ let result ;
65+ while ( ! result ?. done ) {
66+ result = await reader . read ( new Uint8Array ( 8 ) ) ;
67+ }
68+
69+ channel . unsubscribe ( subscriber ) ;
70+ }
You can’t perform that action at this time.
0 commit comments