Stream: git-wasmtime

Topic: wasmtime / PR #10586 doc: fixup `Pollable` example


view this post on Zulip Wasmtime GitHub notifications bot (Apr 15 2025 at 15:17):

rvolosatovs opened PR #10586 from rvolosatovs:doc/pollable-fixup to bytecodealliance:main:

Usage example for wasmtime_wasi::Pollable is displayed as:

Instant) {} } }
use tokio::time::{self, Duration, Instant};
use wasmtime_wasi_io::{IoView, poll::{Pollable, subscribe, DynPollable}, async_trait};
use wasmtime::component::Resource;
use wasmtime::Result;

fn sleep(cx: &mut dyn IoView, dur: Duration) -> Result<Resource<DynPollable>> {
    let end = Instant::now() + dur;
    let sleep = MySleep { end };
    let sleep_resource = cx.table().push(sleep)?;
    subscribe(cx.table(), sleep_resource)
}

struct MySleep {
    end: Instant,
}

#[async_trait]
impl Pollable for MySleep {
    async fn ready(&mut self) {
        tokio::time::sleep_until(self.end).await;
    }
}

which would not compile, if it were duplicated.

Note, that the doctests do not catch this issue, since the Rust code in the source is valid, however the displayed one is not due to # only hiding part of the implementation

view this post on Zulip Wasmtime GitHub notifications bot (Apr 15 2025 at 15:17):

rvolosatovs requested wasmtime-core-reviewers for a review on PR #10586.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 15 2025 at 15:17):

rvolosatovs requested alexcrichton for a review on PR #10586.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 15 2025 at 15:17):

rvolosatovs edited PR #10586:

Usage example for wasmtime_wasi::Pollable in v31.0.0 is displayed as:

Instant) {} } }
use tokio::time::{self, Duration, Instant};
use wasmtime_wasi_io::{IoView, poll::{Pollable, subscribe, DynPollable}, async_trait};
use wasmtime::component::Resource;
use wasmtime::Result;

fn sleep(cx: &mut dyn IoView, dur: Duration) -> Result<Resource<DynPollable>> {
    let end = Instant::now() + dur;
    let sleep = MySleep { end };
    let sleep_resource = cx.table().push(sleep)?;
    subscribe(cx.table(), sleep_resource)
}

struct MySleep {
    end: Instant,
}

#[async_trait]
impl Pollable for MySleep {
    async fn ready(&mut self) {
        tokio::time::sleep_until(self.end).await;
    }
}

which would not compile, if it were duplicated.

Note, that the doctests do not catch this issue, since the Rust code in the source is valid, however the displayed one is not due to # only hiding part of the implementation

view this post on Zulip Wasmtime GitHub notifications bot (Apr 15 2025 at 15:19):

alexcrichton submitted PR review.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 15 2025 at 15:19):

alexcrichton has enabled auto merge for PR #10586.

view this post on Zulip Wasmtime GitHub notifications bot (Apr 15 2025 at 15:54):

alexcrichton merged PR #10586.


Last updated: Dec 06 2025 at 06:05 UTC