-
Notifications
You must be signed in to change notification settings - Fork 995
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(wasm-ext): Add web-sys WebTransport
- Loading branch information
Showing
11 changed files
with
849 additions
and
15 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
mod cached_js_promise; | ||
mod connection; | ||
mod error; | ||
mod substream; | ||
mod transport; | ||
mod utils; | ||
|
||
pub use self::connection::Connection; | ||
pub use self::error::Error; | ||
pub use self::substream::Substream; | ||
pub use self::transport::{Config, Transport}; |
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,48 @@ | ||
use futures::FutureExt; | ||
use js_sys::Promise; | ||
use send_wrapper::SendWrapper; | ||
use std::task::{ready, Context, Poll}; | ||
use wasm_bindgen::JsValue; | ||
use wasm_bindgen_futures::JsFuture; | ||
|
||
pub struct CachedJsPromise { | ||
cached: Option<SendWrapper<JsFuture>>, | ||
} | ||
|
||
impl CachedJsPromise { | ||
pub fn new() -> Self { | ||
CachedJsPromise { cached: None } | ||
} | ||
|
||
pub fn maybe_init_and_poll<F>( | ||
&mut self, | ||
cx: &mut Context, | ||
init: F, | ||
) -> Poll<Result<JsValue, JsValue>> | ||
where | ||
F: FnOnce() -> Promise, | ||
{ | ||
if self.cached.is_none() { | ||
self.cached = Some(SendWrapper::new(JsFuture::from(init()))); | ||
} | ||
|
||
self.poll(cx) | ||
} | ||
|
||
pub fn poll(&mut self, cx: &mut Context) -> Poll<Result<JsValue, JsValue>> { | ||
let val = ready!(self | ||
.cached | ||
.as_mut() | ||
.expect("CachedJsPromise not initialized") | ||
.poll_unpin(cx)); | ||
|
||
// Future finished, drop it | ||
self.cached.take(); | ||
|
||
Poll::Ready(val) | ||
} | ||
|
||
pub fn is_active(&self) -> bool { | ||
self.cached.is_some() | ||
} | ||
} |
Oops, something went wrong.