Skip to main content

FerroSynchronizationContext

Struct FerroSynchronizationContext 

Source
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

Source

pub fn new() -> Arc<Self> ⓘ

Creates a context for the current thread’s dispatcher at DispatcherPriority::DEFAULT.

Source

pub fn with_priority(priority: DispatcherPriority) -> Arc<Self> ⓘ

Creates a context for the current thread’s dispatcher.

Source

pub fn with_dispatcher( dispatcher: &Arc<Dispatcher>, priority: DispatcherPriority, ) -> Arc<Self> ⓘ

Source

pub fn priority(&self) -> DispatcherPriority

The priority at which this context queues work.

Source

pub fn dispatcher(&self) -> &Arc<Dispatcher> ⓘ

Source

pub fn current() -> Option<Arc<FerroSynchronizationContext>>

The context of the calling thread.

Source

pub fn set_current( context: Option<Arc<FerroSynchronizationContext>>, ) -> Option<Arc<FerroSynchronizationContext>>

Sets the context of the calling thread and returns the previous one.

Source

pub fn auto_install() -> bool

Controls whether install_if_needed does anything.

Source

pub fn set_auto_install(value: bool)

Source

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.

Source

pub fn post(&self, callback: impl FnOnce() + Send + 'static)

Queues callback on the dispatcher at the priority of this context.

Source

pub fn post_local(&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.

Source

pub fn send(&self, callback: impl FnOnce() + Send + 'static)

Runs callback on the dispatcher thread and waits for it.

Source

pub fn send_local(&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.

Source

pub fn to_task_scheduler(self: &Arc<Self>) -> DispatcherTaskScheduler

The scheduler that runs futures on the dispatcher at the priority of this context.

Source

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.

Source

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.

Source§

fn post(&self, work: Box<dyn FnOnce() + Send>)

Queues work to run on the context, from any thread, without waiting for it (Post).
Source§

fn send(&self, work: Box<dyn FnOnce() + Send>)

Runs work on the context, from any thread, and waits for it (Send).
Source§

fn post_local(&self, work: Box<dyn FnOnce()>)

Queues 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()>)

Runs 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)

Tells the context that an operation has started (OperationStarted); nothing by default.
Source§

fn operation_completed(&self)

Tells the context that an operation has completed (OperationCompleted); nothing by default.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ClassDefaults for T
where T: ?Sized,

Source§

fn static_constructor()

The static constructor of a type: work done once per thread, after the properties of the type are registered and before its first instance exists (class handlers, affects_render, metadata overrides). Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.