pub struct FerroSynchronizationContext { /* private fields */ }Expand description
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::to_task_scheduler) 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.
Implementations§
Source§impl FerroSynchronizationContext
impl FerroSynchronizationContext
Sourcepub fn new() -> Arc<Self> ⓘ
pub fn new() -> Arc<Self> ⓘ
Creates a context for the current thread’s dispatcher at
DispatcherPriority::DEFAULT.
Sourcepub fn with_priority(priority: DispatcherPriority) -> Arc<Self> ⓘ
pub fn with_priority(priority: DispatcherPriority) -> Arc<Self> ⓘ
Creates a context for the current thread’s dispatcher.
pub fn with_dispatcher( dispatcher: &Arc<Dispatcher>, priority: DispatcherPriority, ) -> Arc<Self> ⓘ
Sourcepub fn priority(&self) -> DispatcherPriority
pub fn priority(&self) -> DispatcherPriority
The priority at which this context queues work.
pub fn dispatcher(&self) -> &Arc<Dispatcher> ⓘ
Sourcepub fn current() -> Option<Arc<FerroSynchronizationContext>>
pub fn current() -> Option<Arc<FerroSynchronizationContext>>
The context of the calling thread.
Sourcepub fn set_current(
context: Option<Arc<FerroSynchronizationContext>>,
) -> Option<Arc<FerroSynchronizationContext>>
pub fn set_current( context: Option<Arc<FerroSynchronizationContext>>, ) -> Option<Arc<FerroSynchronizationContext>>
Sets the context of the calling thread and returns the previous one.
Sourcepub fn auto_install() -> bool
pub fn auto_install() -> bool
Controls whether install_if_needed does
anything.
pub fn set_auto_install(value: bool)
Sourcepub fn install_if_needed()
pub fn install_if_needed()
Makes the DispatcherPriority::NORMAL context of the current
thread’s dispatcher the current context, unless the thread already
has one.
Sourcepub fn post(&self, callback: impl FnOnce() + Send + 'static)
pub fn post(&self, callback: impl FnOnce() + Send + 'static)
Queues callback on the dispatcher at the priority of this context.
Sourcepub fn post_local(&self, callback: impl FnOnce() + 'static)
pub fn post_local(&self, callback: impl FnOnce() + 'static)
Sourcepub fn send(&self, callback: impl FnOnce() + Send + 'static)
pub fn send(&self, callback: impl FnOnce() + Send + 'static)
Runs callback on the dispatcher thread and waits for it.
Sourcepub fn send_local(&self, callback: impl FnOnce() + 'static)
pub fn send_local(&self, callback: impl FnOnce() + 'static)
Sourcepub fn to_task_scheduler(self: &Arc<Self>) -> DispatcherTaskScheduler
pub fn to_task_scheduler(self: &Arc<Self>) -> DispatcherTaskScheduler
The scheduler that runs futures on the dispatcher at the priority of this context.
Sourcepub fn ensure(priority: DispatcherPriority) -> RestoreContext
pub 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.
Sourcepub fn ensure_with_dispatcher(
dispatcher: &Dispatcher,
priority: DispatcherPriority,
) -> RestoreContext
pub 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§
Source§impl SynchronizationContext for FerroSynchronizationContext
The context as a System.Threading.SynchronizationContext of ferroui-system, for the code
that is not tied to the user interface (the reactive libraries, the tasks of ferroui-system):
each member is the method of the same name above.
impl SynchronizationContext for FerroSynchronizationContext
The context as a System.Threading.SynchronizationContext of ferroui-system, for the code
that is not tied to the user interface (the reactive libraries, the tasks of ferroui-system):
each member is the method of the same name above.
Source§fn post(&self, work: Box<dyn FnOnce() + Send>)
fn post(&self, work: Box<dyn FnOnce() + Send>)
work to run on the context, from any thread, without waiting for it (Post).Source§fn send(&self, work: Box<dyn FnOnce() + Send>)
fn send(&self, work: Box<dyn FnOnce() + Send>)
work on the context, from any thread, and waits for it (Send).Source§fn post_local(&self, work: Box<dyn FnOnce()>)
fn post_local(&self, work: Box<dyn FnOnce()>)
work, which is not Send, to run on the context (Post from the thread of the
context). Implementations may panic when it is called from another thread.Source§fn send_local(&self, work: Box<dyn FnOnce()>)
fn send_local(&self, work: Box<dyn FnOnce()>)
work, which is not Send, on the context and waits for it (Send from the thread of
the context). Implementations may panic when it is called from another thread.Source§fn operation_started(&self)
fn operation_started(&self)
OperationStarted); nothing by default.Source§fn operation_completed(&self)
fn operation_completed(&self)
OperationCompleted); nothing by
default.Auto Trait Implementations§
impl Freeze for FerroSynchronizationContext
impl RefUnwindSafe for FerroSynchronizationContext
impl Send for FerroSynchronizationContext
impl Sync for FerroSynchronizationContext
impl Unpin for FerroSynchronizationContext
impl UnsafeUnpin for FerroSynchronizationContext
impl UnwindSafe for FerroSynchronizationContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ClassDefaults for Twhere
T: ?Sized,
impl<T> ClassDefaults for Twhere
T: ?Sized,
Source§fn static_constructor()
fn static_constructor()
affects_render, metadata
overrides). Read more