Skip to content

Commit

Permalink
clean up implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan-Arrowood committed May 10, 2024
1 parent 351c9d5 commit 22ee398
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 3 additions & 3 deletions packages/next/src/server/stream-utils/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function streamToString(
stream: Readable | ReadableStream
): Promise<string>

export function chainStreams<T>(
...streams: ReadableStream<T>[]
): ReadableStream<T>
export function chainStreams(
...streams: ReadableStream<Uint8Array>[]
): ReadableStream<Uint8Array>
export function chainStreams(...streams: Readable[]): Readable
15 changes: 12 additions & 3 deletions packages/next/src/server/stream-utils/stream-utils.node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
* By default, this file exports the methods from streams-utils.edge since all of those are based on Node.js web streams.
* This file will then be an incremental re-implementation of all of those methods into Node.js only versions (based on proper Node.js Streams).
*/
import { PassThrough, type Readable, Transform, Writable, pipeline } from 'node:stream'
import {
PassThrough,
type Readable,
Transform,
Writable,
pipeline,
} from 'node:stream'
import type { Options as RenderToPipeableStreamOptions } from 'react-dom/server.node'
import { StringDecoder } from 'node:string_decoder'

Expand Down Expand Up @@ -87,8 +93,11 @@ export function chainStreams(...streams: Readable[]): Readable {

const transform = new Transform()

pipeline(streams, transform, () => {
/* do nothing */
pipeline(streams, transform, (err) => {
// to match `stream-utils.edge.ts`, this error is just ignored.
// but maybe we at least log it?
console.log(`Invariant: error when pipelining streams`)
console.error(err)
})

return transform
Expand Down

0 comments on commit 22ee398

Please sign in to comment.