Can someone please explain to me how the interaction of the browser, the js runtime, the rust wasmtime, and spawn_local in wasm_bindgen_futures - Rust work together ?
My current intuition (based on guessing) is:
- we store this future on some queue
- there is some rust/JS 'ticker', similar to a
.requestAnimaionFrame, that every now and then goes through the queue and runs the asyncs
Promise into a
JsFuture it will generate a refcounted state. This state will optionally contain a task waker. When creating the
.then() is called on the
Promise with a closure that signals the task waker on completion and stores the result in the refcounted state. When you poll a
JsFuture it will either return the result value if the promise was already completed or store the current task waker in the state of the
spawn_local will The task waker will queue the task onto a global queue. This queue works by calling
.then() on a
Promise already resolved to the
undefined JS value. I would guess this is done to prevent reentrancy problems in case a future immediately calls the waker and to keep the stack smaller.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.