Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kflansburg committed Mar 22, 2024
1 parent 4d5c166 commit 4e5ad18
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 30 deletions.
2 changes: 1 addition & 1 deletion worker/src/http/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn from_wasm(req: web_sys::Request) -> Result<http::Request<Body>> {
})
}

/// **Requires** `http` feature. Convert [`worker::HttpRequest`](crate::HttpRequest)
/// **Requires** `http` feature. Convert [`http::Request`](http::Request)
/// to [`web_sys::Request`](web_sys::Request)
pub fn to_wasm<B: http_body::Body<Data = Bytes> + 'static>(
mut req: http::Request<B>,
Expand Down
2 changes: 1 addition & 1 deletion worker/src/http/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
)?)
}

/// **Requires** `http` feature. Convert [`web_sys::Resopnse`](web_sys::Response)
/// **Requires** `http` feature. Convert [`web_sys::Response`](web_sys::Response)
/// to [`worker::HttpResponse`](crate::HttpResponse)
pub fn from_wasm(res: web_sys::Response) -> Result<HttpResponse> {
let mut builder =
Expand Down
27 changes: 0 additions & 27 deletions worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ pub use crate::env::{Env, EnvBinding, Secret, Var};
pub use crate::error::Error;
pub use crate::fetcher::Fetcher;
pub use crate::formdata::*;
// #[cfg(not(feature="http"))]
pub use crate::global::Fetch;
pub use crate::headers::Headers;
pub use crate::http::Method;
Expand Down Expand Up @@ -166,11 +165,8 @@ pub mod durable;
mod dynamic_dispatch;
mod env;
mod error;
// #[cfg(feature = "http")]
// mod fetch;
mod fetcher;
mod formdata;
// #[cfg(not(feature="http"))]
mod global;
mod headers;
mod http;
Expand Down Expand Up @@ -203,26 +199,3 @@ pub type HttpRequest = ::http::Request<http::body::Body>;
#[cfg(feature = "http")]
/// **Requires** `http` feature. Type alias for `http::Response<worker::Body>`.
pub type HttpResponse = ::http::Response<http::body::Body>;

struct SendJsFuture(wasm_bindgen_futures::JsFuture);

unsafe impl Send for SendJsFuture {}
unsafe impl Sync for SendJsFuture {}

impl futures_util::Future for SendJsFuture {
type Output = std::result::Result<wasm_bindgen::JsValue, wasm_bindgen::JsValue>;
fn poll(
self: std::pin::Pin<&mut Self>,
cx: &mut std::task::Context<'_>,
) -> std::task::Poll<Self::Output> {
use futures_util::FutureExt;
let inner = &mut self.get_mut().0;
inner.poll_unpin(cx)
}
}

impl From<js_sys::Promise> for SendJsFuture {
fn from(value: js_sys::Promise) -> Self {
SendJsFuture(wasm_bindgen_futures::JsFuture::from(value))
}
}
2 changes: 1 addition & 1 deletion worker/src/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ async fn fetch_with_request_raw(request: crate::Request) -> Result<web_sys::Resp
let req = request.inner();
let fut = {
let worker: web_sys::WorkerGlobalScope = js_sys::global().unchecked_into();
crate::SendJsFuture(JsFuture::from(worker.fetch_with_request(req)))
crate::send::SendFuture::new(JsFuture::from(worker.fetch_with_request(req)))
};
let resp = fut.await?;
Ok(resp.dyn_into()?)
Expand Down

0 comments on commit 4e5ad18

Please sign in to comment.