NAME
Reflex::Callback::Promise - Condvar-like non-callback adapter
VERSION
version 0.010
SYNOPSIS
Used within Reflex:
use Reflex::Timer;
use ExampleHelpers qw(eg_say);
my $pt = Reflex::Timer->new(
interval => 1 + rand(),
auto_repeat => 1,
);
while (my $event = $pt->wait()) {
eg_say("promise timer returned an event (@$event)");
}
Low-level usage:
use Reflex::Callback::Promise;
my $cb = Reflex::Callback::Promise->new();
$cb->deliver( greet => { name => "world" } );
my $event = $cb->wait();
print "event '$event->{name}': hello, $event->{arg}{name}\n";
DESCRIPTION
Reflex::Callback::Promise maps the generic Reflex::Callback interface to non-callback promises, which are kind of like condvars. In most cases, Reflex::Callbacks' cb_promise() or other syntactic sweeteners will be used instead of raw Reflex::Callback::Promise objects.
new
Reflex::Callback::Promise's constructor takes no parameters. It creates a promise queue that is populated by deliver() and drained by wait(). Furthermore, wait() will block as necessary until it can return an event. This requires the help of some form of concurrency, currently hardcoded to use POE.
A future version may delegate the POE dependency to a subclass.
wait
Reflex::Callback::Promise's wait() method retrieves the next pending event held in the object's queue. If the queue is empty, wait() will dispatch other events until some asynchronous code enqueues a new event in the promise's queue.
deliver
Reflex::Callback::Promise's deliver() enqueues events for the promise. As with other Reflex::Callback subclasses, this deliver() accepts two positional parameters: an event name (which IS used), and a hashref of named parameters to be passed to the callback.
Deliver doesn't return anything meaningful, since the code to handle the event isn't executed at the time of delivery.
SEE ALSO
Reflex Reflex::Callback Reflex::Callbacks
"ACKNOWLEDGEMENTS" in Reflex "ASSISTANCE" in Reflex "AUTHORS" in Reflex "BUGS" in Reflex "BUGS" in Reflex "CONTRIBUTORS" in Reflex "COPYRIGHT" in Reflex "LICENSE" in Reflex "TODO" in Reflex