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,
},
},
},
}
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: Dec 23 2024 at 12:05 UTC