Skip to content

Commit

Permalink
chore: small cleanups (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Nov 6, 2023
1 parent dd5c0e1 commit bfadd47
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ export class Stream<Item> implements AsyncIterable<Item> {
return new Stream(iterator, controller);
}

// Generates a Stream from a newline-separated ReadableStream where each item
// is a JSON Value.
/**
* Generates a Stream from a newline-separated ReadableStream
* where each item is a JSON value.
*/
static fromReadableStream<Item>(readableStream: ReadableStream, controller: AbortController) {
let consumed = false;

Expand Down Expand Up @@ -138,6 +140,10 @@ export class Stream<Item> implements AsyncIterable<Item> {
return this.iterator();
}

/**
* Splits the stream into two streams which can be
* independently read from at different speeds.
*/
tee(): [Stream<Item>, Stream<Item>] {
const left: Array<Promise<IteratorResult<Item>>> = [];
const right: Array<Promise<IteratorResult<Item>>> = [];
Expand All @@ -162,8 +168,11 @@ export class Stream<Item> implements AsyncIterable<Item> {
];
}

// Converts this stream to a newline-separated ReadableStream of JSON Stringified values in the stream
// which can be turned back into a Stream with Stream.fromReadableStream.
/**
* Converts this stream to a newline-separated ReadableStream of
* JSON stringified values in the stream
* which can be turned back into a Stream with `Stream.fromReadableStream()`.
*/
toReadableStream(): ReadableStream {
const self = this;
let iter: AsyncIterator<Item>;
Expand Down

0 comments on commit bfadd47

Please sign in to comment.