-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fix support for stream.Readable in browsers
- Since wasm-bindgen doesn't support a way to extend JavaScript classes (rustwasm/wasm-bindgen#210), add a basic JavaScript shim, that pushes the data available in Rust to the Readable in JavaScript. - use channels and spawn_local in Rust to move along Stream iterator and pass results to enqueue for read() (in the JavaScript shim) - adds an abort controller that will abort the stream in JavaScript is a stream error occurs in Rust
- Loading branch information
Showing
3 changed files
with
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Provide a JavaScript shim for the WAS-based ReadableStream, so we can use it in | ||
// the browser and we can use the ES6-style classes | ||
|
||
const { Readable } = require("readable-stream"); | ||
|
||
const makeReadable = (readFn, abort) => { | ||
return new Readable({ | ||
read(size) { | ||
this.push(readFn(size)); | ||
}, | ||
|
||
signal: abort, | ||
}); | ||
}; | ||
|
||
module.exports = { makeReadable }; |
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