Replies: 2 comments
-
Replacing the The main reason for that is because That basically rules out using a standard Even if you do that though, there's still another roadblock to making the future So, the only way to do that would be to just... not clear timeouts on drop. You'd also then have to use An alternative, since you said that you aren't intending to support multithreading, would just be to unsafely declare your future |
Beta Was this translation helpful? Give feedback.
-
@Liamolucko After all, I think having
(I didn't begin working in these things yet, not even the graphics API.)
Interesting, it looks like
I honestly didn't find that cancelling timeouts on
Here's what I've for pub fn background_animation_interval(callback: Box<(dyn Fn(Duration) + Send + Sync + 'static)>, period: Duration) -> BackgroundInterval {
let mut stopped = Arc::new(RwLock::new(false));
exec_future({
let stopped = Arc::clone(&mut stopped);
async move {
let mut interval = animation_interval(period);
interval.tick().await;
loop {
let delta = interval.tick().await;
if *stopped.read().unwrap() {
break;
}
callback(delta);
}
}
});
BackgroundInterval {
stopped,
}
} |
Beta Was this translation helpful? Give feedback.
-
Motivation
I've a timing API which uses either the Tokio runtime or the browser. The problem is that Tokio timing functions return a future with a
Send
bound andJsFuture
doesn't implementSend
due to containing anRc
.I'm not planning to expose a thread API in my framework; rather, I'll have a gaming API that uses concurrent systems only on some platforms, excluding the browser (in default platforms, the gaming API would create threads internally).
Proposed Solution
Put an
Arc
inside instead with aRwLock
inside instead ofRc<RefCell>
.Alternatives
N/A
Additional Context
N/A
Beta Was this translation helpful? Give feedback.
All reactions