-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ReadableStreams): Support for ReadableStreams e.g. `from(readabl…
…eStream)` (#6163) * feat(ReadableStreams): Support for ReadableStreams e.g. `from(readableStream)` * feat(ReadableStreams): stub ReadableStreamDefaultReader type definition. * feat(ReadableStreams): add comments. * refactor: Export ReadableStreamLike, add dtslint test * chore: update imports and api_guardian golden files Co-authored-by: Ben Lesh <[email protected]>
- Loading branch information
Showing
11 changed files
with
195 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { SchedulerLike, ReadableStreamLike } from '../types'; | ||
import { Observable } from '../Observable'; | ||
import { scheduleAsyncIterable } from './scheduleAsyncIterable'; | ||
import { readableStreamLikeToAsyncGenerator } from '../util/isReadableStreamLike'; | ||
|
||
export function scheduleReadableStreamLike<T>(input: ReadableStreamLike<T>, scheduler: SchedulerLike): Observable<T> { | ||
return scheduleAsyncIterable(readableStreamLikeToAsyncGenerator(input), scheduler); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { ReadableStreamLike } from '../types'; | ||
import { isFunction } from './isFunction'; | ||
|
||
export async function* readableStreamLikeToAsyncGenerator<T>(readableStream: ReadableStreamLike<T>): AsyncGenerator<T> { | ||
const reader = readableStream.getReader(); | ||
try { | ||
while (true) { | ||
const { value, done } = await reader.read(); | ||
if (done) { | ||
return; | ||
} | ||
yield value!; | ||
} | ||
} finally { | ||
reader.releaseLock(); | ||
} | ||
} | ||
|
||
export function isReadableStreamLike<T>(obj: any): obj is ReadableStreamLike<T> { | ||
// We don't want to use instanceof checks because they would return | ||
// false for instances from another Realm, like an <iframe>. | ||
return isFunction(obj?.getReader); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters