Skip to content

Commit

Permalink
perf: update MultiplyStream to accept ReadableWritablePair
Browse files Browse the repository at this point in the history
The `MultiplyStream` class and its associated tests have been updated to accept a `ReadableWritablePair` object instead of a direct `WritableStream`. This modification allows for more flexibility and aligns with common patterns in readable and writable stream manipulations. The change entails adjusting both the constructor's input type and the way writers are instantiated within the `MultiplyStream` class. Consequently, this enhances the class's usability by supporting scenarios that may involve additional stream-related features or requirements encapsulated within a `ReadableWritablePair`. The test updates demonstrate this new capability by adjusting the input format accordingly, ensuring continued compatibility and functionality.
  • Loading branch information
JonDotsoy committed Mar 9, 2024
1 parent c4496da commit 333f6c6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
16 changes: 10 additions & 6 deletions src/multiply-stream.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ test("", async () => {
},
}).pipeThrough(
new MultiplyStream(
new WritableStream({
write: (chunk) => obj1.call(chunk),
}),
new WritableStream({
write: (chunk) => obj1.call(chunk),
}),
{
writable: new WritableStream({
write: (chunk) => obj1.call(chunk),
}),
},
{
writable: new WritableStream({
write: (chunk) => obj1.call(chunk),
}),
},
),
);

Expand Down
8 changes: 4 additions & 4 deletions src/multiply-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export class MultiplyStream<T> implements ReadableWritablePair<T, T> {
controller: ReadableStreamDefaultController<T>;
writable: WritableStream<T>;

constructor(...writables: WritableStream<T>[]) {
const writers = writables.map((writable) => ({
writable,
writer: writable.getWriter(),
constructor(...readableWritablePairs: { writable: WritableStream<T> }[]) {
const writers = readableWritablePairs.map((readableWritablePair) => ({
writable: readableWritablePair.writable,
writer: readableWritablePair.writable.getWriter(),
}));
const { readable, controller } = readableStreamWithController<T>();
this.readable = readable;
Expand Down

0 comments on commit 333f6c6

Please sign in to comment.