[][src]Macro stakker::call

macro_rules! call {
    ( $($x:tt)+ ) => { ... };
}

Queue an actor call, forward call or inline code for execution soon

The call is deferred to the main defer queue, which will execute as soon as possible.

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 or Fwd instance. All of these values may be full Rust expressions. Exceptions are method names, types/paths and argument names for closures which may be any valid identifier.

Note that the context or core reference is included in the argument lists to make the form of the argument list look similar to the signature of the method. However this core or context reference is only used to add the call to the queue or to obtain a reference to the current actor. When the call executes it will be given a fresh context.

This example is not tested
// Call a method in this actor or in another actor
call!(method(cx, arg1, arg2...));
call!([actorxx], method(core, arg1, arg2...));

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

// Forward data, using a `Fwd` instance
call!([fwd2zz], core, arg1, arg2...);

// Defer a call to inline code
call!(cx, |this, cx| { ...code... });  // Inline code which refers to this actor
call!(cx, move |this, cx| { ...code... });
call!(core, |stakker| { ...code... }); // Generic inline code (`&mut Stakker` arg)
call!(core, move |stakker| { ...code... });

Note that call! also supports using Deferrer in place of core in some of the forms above.

This example is not tested
call!([actorxx], method(deferrer, arg1, arg2...));
call!([actoryy], Type::method(deferrer, arg1, arg2...));
call!([actorzz], <path::Type>::method(deferrer, arg1, arg2...));

When using Deferrer to send a message to a Fwd instance it's necessary to do it in two stages, because Fwd instances need access to the main queue. So defer the forward call:

This example is not tested
deferrer.defer(|s| call!([fwd2zz], s, arg1, arg2...));

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