Skip to content

Commit

Permalink
Use pin_project and make ContinuousPoll generic
Browse files Browse the repository at this point in the history
  • Loading branch information
Oliver Scherer committed Nov 29, 2023
1 parent d31ac01 commit e322ce1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ version = "0.7.1"

[dependencies]
bevy = {version = "0.12", default-features = false, features = ["bevy_asset"]}
pin-project = "1.1.3"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
isahc = "1"
Expand Down
13 changes: 7 additions & 6 deletions src/web_asset_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,20 @@ async fn get<'a>(path: PathBuf) -> Result<Box<Reader<'a>>, AssetReaderError> {
use std::pin::Pin;
use std::task::{Context, Poll};

use isahc::get_async;
use isahc::http::StatusCode;
use isahc::{get_async, AsyncBody, Error, Response, ResponseFuture};

struct ContinuousPoll<'a>(ResponseFuture<'a>);
#[pin_project::pin_project]
struct ContinuousPoll<T>(#[pin] T);

impl<'a> Future for ContinuousPoll<'a> {
type Output = Result<Response<AsyncBody>, Error>;
impl<T: Future> Future for ContinuousPoll<T> {
type Output = T::Output;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
// Always wake - blocks on single threaded executor.
cx.waker().wake_by_ref();

Pin::new(&mut self.0).poll(cx)
self.project().0.poll(cx)
}
}

Expand Down

0 comments on commit e322ce1

Please sign in to comment.