Skip to content

Commit

Permalink
Bring back error handling for tee()
Browse files Browse the repository at this point in the history
  • Loading branch information
MattiasBuelens committed Sep 30, 2023
1 parent e48278a commit b2d0e69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/readable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,11 @@ impl ReadableStream {
/// If the stream is already locked to a reader, then this returns an error
/// along with the original `ReadableStream`.
pub fn try_tee(self) -> Result<(ReadableStream, ReadableStream), (js_sys::Error, Self)> {
if self.is_locked() {
return Err((js_sys::Error::new("Already locked"), self));
}
let branches = self.as_raw().tee();
let branches = self
.as_raw()
.unchecked_ref::<sys::ReadableStreamExt>()
.try_tee()
.map_err(|err| (err, self))?;
debug_assert_eq!(branches.length(), 2);
let (left, right) = (branches.get(0), branches.get(1));
Ok((
Expand Down
5 changes: 4 additions & 1 deletion src/readable/sys.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Raw bindings to JavaScript objects used
//! by a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream).
//! These are re-exported from [web-sys](https://docs.rs/web-sys/0.3.64/web_sys/struct.ReadableStream.html).
use js_sys::{Error, Object, Uint8Array};
use js_sys::{Array, Error, Object, Uint8Array};
use wasm_bindgen::prelude::*;
pub use web_sys::ReadableByteStreamController;
// Re-export from web-sys
Expand All @@ -27,6 +27,9 @@ extern "C" {
this: &ReadableStreamExt,
options: &ReadableStreamGetReaderOptions,
) -> Result<Object, Error>;

#[wasm_bindgen(method, catch, js_name = tee)]
pub(crate) fn try_tee(this: &ReadableStreamExt) -> Result<Array, Error>;
}

#[wasm_bindgen]
Expand Down

0 comments on commit b2d0e69

Please sign in to comment.