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§
Sourcefn post(&self, work: Box<dyn FnOnce() + Send>)
fn post(&self, work: Box<dyn FnOnce() + Send>)
Queues work to run on the context, from any thread, without waiting for it (Post).
Sourcefn send(&self, work: Box<dyn FnOnce() + Send>)
fn send(&self, work: Box<dyn FnOnce() + Send>)
Runs work on the context, from any thread, and waits for it (Send).
Sourcefn post_local(&self, work: Box<dyn FnOnce()>)
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.
Sourcefn send_local(&self, work: Box<dyn FnOnce()>)
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§
Sourcefn operation_started(&self)
fn operation_started(&self)
Tells the context that an operation has started (OperationStarted); nothing by default.
Sourcefn operation_completed(&self)
fn operation_completed(&self)
Tells the context that an operation has completed (OperationCompleted); nothing by
default.
Implementations§
Source§impl dyn SynchronizationContext
impl dyn SynchronizationContext
Sourcepub fn current() -> Option<Arc<dyn SynchronizationContext>>
pub fn current() -> Option<Arc<dyn SynchronizationContext>>
The current context of the calling thread (SynchronizationContext.Current); the same as
current_synchronization_context.
Sourcepub fn set_synchronization_context(
context: Option<Arc<dyn SynchronizationContext>>,
)
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.
Sourcepub fn is_current(context: &Arc<dyn SynchronizationContext>) -> bool
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".