Sha256: 7ebaddfb47640ebebc894586fcdaf481c28f6247ba6118e500984760a42a5a34

Contents?: true

Size: 779 Bytes

Versions: 11

Compression:

Stored size: 779 Bytes

Contents

use core::{
    future::Future,
    pin::Pin,
    task::{Context, Poll},
};

/// A small future that yields once and then returns.
#[derive(Default)]
pub struct Yield {
    yielded: bool,
}

impl Yield {
    /// Create a new `Yield`.
    pub fn new() -> Self {
        Self::default()
    }
}

impl Future for Yield {
    type Output = ();

    fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
        if self.yielded {
            Poll::Ready(())
        } else {
            // Flag ourselves as yielded to return next time, and also
            // flag the waker that we're already ready to get
            // re-enqueued for another poll.
            self.yielded = true;
            cx.waker().wake_by_ref();
            Poll::Pending
        }
    }
}

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/wasmtime-29.0.0/src/runtime/vm/async_yield.rs
wasmtime-28.0.0 ./ext/cargo-vendor/wasmtime-28.0.0/src/runtime/vm/async_yield.rs
wasmtime-27.0.0 ./ext/cargo-vendor/wasmtime-27.0.0/src/runtime/vm/async_yield.rs
wasmtime-26.0.0 ./ext/cargo-vendor/wasmtime-26.0.0/src/runtime/vm/async_yield.rs
wasmtime-25.0.2 ./ext/cargo-vendor/wasmtime-25.0.2/src/runtime/vm/async_yield.rs
wasmtime-25.0.1 ./ext/cargo-vendor/wasmtime-25.0.1/src/runtime/vm/async_yield.rs
wasmtime-25.0.0 ./ext/cargo-vendor/wasmtime-25.0.0/src/runtime/vm/async_yield.rs
wasmtime-24.0.0 ./ext/cargo-vendor/wasmtime-24.0.0/src/runtime/vm/async_yield.rs
wasmtime-23.0.2 ./ext/cargo-vendor/wasmtime-23.0.2/src/runtime/vm/async_yield.rs
wasmtime-22.0.0 ./ext/cargo-vendor/wasmtime-22.0.0/src/runtime/vm/async_yield.rs
wasmtime-21.0.1 ./ext/cargo-vendor/wasmtime-21.0.1/src/runtime/vm/async_yield.rs