[][src]Struct haiku::app::Context

pub struct Context<A> where
    A: Send
{ pub handler_messenger: Messenger, pub looper: LooperDelegate, pub application: ApplicationDelegate, pub application_state: Arc<Mutex<A>>, }

Execution context for a Handler

All Handers execute in the context of a Looper. The Context object is passed to your Handler in the message_received() method, so that you can interact with other parts of the system.

The context contains three messengers, that may be used to send messages to certain destinations, or to use as reply addresses while sending messages. Additionally, the Context gives access to the current application state.

Fields

handler_messenger: Messenger

The messenger to the current Handler

This Messenger is most useful as a reply address for any messages you are sending out.

looper: LooperDelegate

Interact with the current Looper

This is the Looper that is the context for the current message

Note that in some cases, this will be the same message queue as the application delegate.

application: ApplicationDelegate

Interact with the current Application object

This gives access to the global application struct

application_state: Arc<Mutex<A>>

Access the global Application state

This state is shared among the whole application. It is locked behind a Mutex, to allow thread-safe access. Note that using the application state is 'dangerous', in the sense that it may lead to deadlocks when two interdependent threads are waiting for access to it. Imagine this scenario:

  1. Looper A gets a reference to the application state, locking it.
  2. Looper A sends a Message to Looper B and waits for a reply
  3. Looper B receives the message. While handling that message, it tries to get a reference to the application state. Since the application state is already locks, both threads will be waiting for each other.

There are two best practises:

  1. Do not use synchronous messaging, unless you know what you are doing.
  2. If you do need access to the application state, use the lock() method of the Mutex, and drop the Guard as soon as you are done.

Auto Trait Implementations

impl<A> RefUnwindSafe for Context<A>

impl<A> Send for Context<A>

impl<A> Sync for Context<A>

impl<A> Unpin for Context<A>

impl<A> UnwindSafe for Context<A>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.