pub trait CurrentThreadTaskDriver:
Send
+ Sync
+ 'static {
// Required method
fn dispatch(&self, delivery: CurrentThreadTaskDelivery) -> bool;
// Provided methods
fn is_live(&self) -> bool { ... }
fn on_swept(&self) { ... }
}Expand description
Host-turn dispatcher for the CurrentThread runnable queue.
The NAPI binding registers one weak native threadsafe-function driver per importing environment. Its custom Node-API callback owns the fresh host turn and keeps delivery capabilities out of JavaScript. Scheduling through a fresh host turn is required for soundness: arbitrary futures may invoke their waker while holding internal locks, so polling the runnable inline from that wake can self-deadlock.
Required Methods§
Sourcefn dispatch(&self, delivery: CurrentThreadTaskDelivery) -> bool
fn dispatch(&self, delivery: CurrentThreadTaskDelivery) -> bool
Queue one host turn that will call drive_current_thread_tasks with
CurrentThreadTaskDelivery::capability.
The delivery capability is scoped to this exact host registration and
attempt. The registry maps it back to the executor’s one internal
dispatch capability only while this attempt remains current.
false means this driver can no longer dispatch and must be swept. After
returning true, the driver must eventually call either
acknowledge_current_thread_task_delivery or
fail_current_thread_task_delivery with this exact value. A successful
acknowledgement is accepted only after
drive_current_thread_tasks claimed this exact delivery.
dispatch must return promptly and must not wait on another thread. In
particular it must never block on the thread that will acknowledge or
fail this delivery (for instance by spawning a helper that calls
fail_current_thread_task_delivery and joining it). The executor
calls dispatch from schedule, which may be a waker’s stack: a waker
can be invoked while its producer holds a mutex (futures::Shared wakes
its awaiters under its wakers lock). When a delivery failure turns
terminal, the rejected work is cancelled on the stack of the thread that
failed it, and a rejected future’s destructor may re-lock the very mutex
the blocked waker still holds. A dispatch that waits on that thread
therefore deadlocks with it.
Failing the delivery synchronously from inside dispatch, on the
calling thread, is handled: the executor recognises that stack as a
possible waker’s, moves the rejected work aside and cancels it on the
next clean stack (see CurrentThreadQueue::rejected). Failing or
acknowledging it later, from any thread, is handled too. The Node-API
driver satisfies this contract: it makes one nonblocking
threadsafe-function call and returns false at once when the
environment is closing.
Provided Methods§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".