Skip to main content

SynchronizationContext

Trait SynchronizationContext 

Source
pub trait SynchronizationContext: Send + Sync {
    // Required methods
    fn post(&self, work: Box<dyn FnOnce() + Send>);
    fn send(&self, work: Box<dyn FnOnce() + Send>);
    fn post_local(&self, work: Box<dyn FnOnce()>);
    fn send_local(&self, work: Box<dyn FnOnce()>);

    // Provided methods
    fn operation_started(&self) { ... }
    fn operation_completed(&self) { ... }
}
Expand description

Where posted work runs (System.Threading.SynchronizationContext).

The base class of .NET posts to the thread pool and sends on the calling thread; here every implementation says where its work runs. An implementation is shared between threads, as the contexts of .NET are.

Required Methods§

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.

Provided Methods§

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.

Implementations§

Source§

impl dyn SynchronizationContext

Source

pub fn current() -> Option<Arc<dyn SynchronizationContext>>

The current context of the calling thread (SynchronizationContext.Current); the same as current_synchronization_context.

Source

pub fn set_synchronization_context( context: Option<Arc<dyn SynchronizationContext>>, )

Sets the current context of the calling thread (SynchronizationContext.SetSynchronizationContext); the same as set_synchronization_context.

Source

pub fn is_current(context: &Arc<dyn SynchronizationContext>) -> bool

Whether context is the current context of the calling thread (context == SynchronizationContext.Current, a comparison of references).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§