FerroSynchronizationContext
struct · ferroui-base · v0.5.0
struct FerroSynchronizationContext
A dispatcher together with the priority at which work handed to it is queued.
The current context of a thread tells asynchronous code where and at
which priority to continue. While the dispatcher executes a job, the
current context is the dispatcher's context for the priority of that job;
futures started without an explicit priority (see
Dispatcher::spawn_local) therefore continue at the priority of
the job that started them.
What the reference implementation additionally does in its context - replacing the blocking wait of the runtime with one that does not pump messages - has no counterpart: blocking primitives never run a message pump here.
Deprecated: the current priority is Dispatcher::current_priority (and
Dispatcher::set_current_priority), posting is Dispatcher::post and
Dispatcher::post_local at that priority, and the code that does not
know the dispatcher takes the current schedule of ferroui-system
(ferroui_system::task::current_schedule, the dispatcher's
task_schedule of the priority).
Deprecated since 0.5.0. use
Dispatcher::current_priority,Dispatcher::post/post_localat that priority, or the dispatcher'stask_schedule(priority)
Members
newwith_prioritywith_dispatcherprioritydispatchercurrentset_currentauto_installset_auto_installinstall_if_neededpostpost_localsendsend_localto_task_schedulerensureensure_with_dispatcher
new
fn new() -> Arc<Self>
Creates a context for the current thread's dispatcher at
DispatcherPriority::DEFAULT.
with_priority
fn with_priority(priority: DispatcherPriority) -> Arc<Self>
Creates a context for the current thread's dispatcher.
with_dispatcher
fn with_dispatcher(dispatcher: &Arc<Dispatcher>, priority: DispatcherPriority) -> Arc<Self>
priority
fn priority(self: &Self) -> DispatcherPriority
The priority at which this context queues work.
dispatcher
fn dispatcher(self: &Self) -> &Arc<Dispatcher>
current
fn current() -> Option<Arc<FerroSynchronizationContext>>
The context of the calling thread.
set_current
fn set_current(context: Option<Arc<FerroSynchronizationContext>>) -> Option<Arc<FerroSynchronizationContext>>
Sets the context of the calling thread and returns the previous one. The dispatcher of the
context at its priority becomes the current schedule of the thread
(ferroui_system::task::current_schedule); None clears it.
auto_install
fn auto_install() -> bool
Controls whether install_if_needed does
anything.
set_auto_install
fn set_auto_install(value: bool)
install_if_needed
fn install_if_needed()
Makes the DispatcherPriority::NORMAL context of the current
thread's dispatcher the current context, unless the thread already
has one.
post
fn post(self: &Self, callback: impl FnOnce() -> () + Send + 'static)
Queues callback on the dispatcher at the priority of this context.
post_local
fn post_local(self: &Self, callback: impl FnOnce() -> () + 'static)
Like post for callbacks that are not Send.
Panics
Panics when called from a thread other than the dispatcher thread.
send
fn send(self: &Self, callback: impl FnOnce() -> () + Send + 'static)
Runs callback on the dispatcher thread and waits for it.
send_local
fn send_local(self: &Self, callback: impl FnOnce() -> () + 'static)
Like send for callbacks that are not Send: runs
callback right away.
Panics
Panics when called from a thread other than the dispatcher thread.
to_task_scheduler
fn to_task_scheduler(self: &Arc<Self>) -> DispatcherTaskScheduler
The scheduler that runs futures on the dispatcher at the priority of this context.
Deprecated since 0.5.0. use the dispatcher's
spawn_local_with_priority,spawn_with_priorityorstart_local_with_priorityat the priority of the context
ensure
fn ensure(priority: DispatcherPriority) -> RestoreContext
Makes sure that the current context of the calling thread is the one
of the current dispatcher for priority. Disposing or dropping the
returned value restores the previous context.
ensure_with_dispatcher
fn ensure_with_dispatcher(dispatcher: &Dispatcher, priority: DispatcherPriority) -> RestoreContext
Makes sure that the current context of the calling thread is the one
of dispatcher for priority. Disposing or dropping the returned
value restores the previous context.
Panics
Panics when the context has to change and the calling thread is not the dispatcher thread.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafeClassDefaultsBorrow<T>BorrowMut<T>Into<U>From<T>TryInto<U>TryFrom<U>AnyErasedDestructorIntoEitherSynchronizationContext
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.