Macro stakker::lazy

source ·
macro_rules! lazy {
    ( $($x:tt)+ ) => { ... };
}
Expand description

Lazily perform an actor call or inline code

This queues calls to the lazy queue which is run only after the normal defer queue has been completely exhausted. This can be used to run something at the end of this batch of processing, for example to flush buffers after accumulating data.

Note that in the examples below, in general there can be any number of arguments, including zero. The number of arguments depends on the signature of the called method. All of these values may be full Rust expressions, which are evaluated at the call-site before queuing the call.

Note that the part in square brackets gives the context of the call, which takes one of these forms:

  • [cx]: This is used for calls to the same actor

  • [actor, cx] or [actor, core]: This is used for calls to another actor. The second argument is used to get access to Core which is used to submit the call to the correct queue.

// Call a method in this actor or in another actor
lazy!([cx], method(arg1, arg2...));
lazy!([actorxx, core], method(arg1, arg2...));

// Call a method whilst the actor is in the 'Prep' state, before it
// has a `Self` instance.  `Type` here in the first line may be `Self`.
lazy!([cx], Type::method(arg1, arg2...));
lazy!([cx], <path::Type>::method(arg1, arg2...));
lazy!([actoryy, core], Type::method(arg1, arg2...));
lazy!([actorzz, core], <path::Type>::method(arg1, arg2...));

// Defer a call to inline code.  Closure is always treated as a `move` closure
lazy!([cx], |this, cx| ...code...);   // Inline code which refers to this actor
lazy!([core], |stakker| ...code...);  // Generic inline code (`&mut Stakker` arg)

Implemented using Core::lazy, Actor::apply and Actor::apply_prep.