Stream: general

Topic: WASI timer polling not working


view this post on Zulip Alsan Ali (Mar 22 2022 at 07:24):

I'm trying to call poll_oneoff with a few file descriptor subscriptions and also a clock subscription. I want to be able to print "Hello" in 2 second intervals repeatedly and also handle events related to the file descriptors simultaneously.

I get an invalid input error when trying to call poll. I'm not sure if my clock subscription code is right since I couldn't find any examples online so here it is:

wasi::Subscription {
    userdata: token.0.try_into().unwrap(),
    u: wasi::SubscriptionU {
        tag: wasi::EVENTTYPE_CLOCK.raw(),
        u: wasi::SubscriptionUU {
            clock: wasi::SubscriptionClock {
                id: wasi::CLOCKID_REALTIME,
                timeout: (SystemTime::now().duration_since(UNIX_EPOCH).unwrap()
                    + self.interval)
                    .as_secs() as wasi::Timestamp,
                precision: Duration::from_millis(1).as_secs() as wasi::Timestamp,
                flags: 1,
            },
        },
    },
}

view this post on Zulip Alsan Ali (Mar 22 2022 at 11:41):

Okay nvm, I figured out the problem. WASI doesn't seem to support timer subscriptions besides the monotonic timer.
I'm able to achieve a repeating interval timer (monotonic) by keeping track of how many times it ran and multiplying that number by the timeout (and reregistering the subscription every iteration).


Last updated: Oct 23 2024 at 20:03 UTC