FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

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

    View source

    Deprecated since 0.5.0. use Dispatcher::current_priority, Dispatcher::post/post_local at that priority, or the dispatcher's task_schedule(priority)

    Members

    new

    fn new() -> Arc<Self>
    

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

    Source

    with_priority

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

    Creates a context for the current thread's dispatcher.

    Source

    with_dispatcher

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

    Source

    priority

    fn priority(self: &Self) -> DispatcherPriority
    

    The priority at which this context queues work.

    Source

    dispatcher

    fn dispatcher(self: &Self) -> &Arc<Dispatcher>
    

    Source

    current

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

    The context of the calling thread.

    Source

    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.

    Source

    auto_install

    fn auto_install() -> bool
    

    Controls whether install_if_needed does anything.

    Source

    set_auto_install

    fn set_auto_install(value: bool)
    

    Source

    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.

    Source

    post

    fn post(self: &Self, callback: impl FnOnce() -> () + Send + 'static)
    

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

    Source

    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.

    Source

    send

    fn send(self: &Self, callback: impl FnOnce() -> () + Send + 'static)
    

    Runs callback on the dispatcher thread and waits for it.

    Source

    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.

    Source

    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_priority or start_local_with_priority at the priority of the context

    Source

    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.

    Source

    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.

    Source

    Trait implementations

    • Send
    • Sync
    • Freeze
    • UnsafeUnpin
    • Unpin
    • UnwindSafe
    • RefUnwindSafe
    • ClassDefaults
    • Borrow<T>
    • BorrowMut<T>
    • Into<U>
    • From<T>
    • TryInto<U>
    • TryFrom<U>
    • Any
    • ErasedDestructor
    • IntoEither
    • SynchronizationContext

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.