NAME
UniEvent::Prepare - runs the given callback once before polling for I/O
SYNOPSIS
my $loop = UniEvent::Loop->new;
my $h = UniEvent::Prepare->new($loop);
$h->event->add(sub { say 'hello' });
$h->start;
$loop->run_nowait; # prints 'hello'
$loop->run_nowait; # prints 'hello' again
$h->stop;
$loop->run_nowait; # no effect
$h->reset;
DESCRIPTION
The Prepare handle is useful for doing some actions (in the form of callbacks or listener) before polling I/O. It is inherited from UniEvent::Handle.
If you need to do some actions after polling I/O, consider using UniEvent::Check.
METHODS
new([$loop = UniEvent::Loop->default_loop])
Constructs new Prepare handle and binds it to the specified event loop
start([$callback = undef])
Starts the prepare handle, i.e. makes it active for the next even loop iteration. Optionally it adds the $callback
to the event listeners.
stop()
Stops the prepare handle, i.e. makes it inactive for the next event loop iteration.
callback($code)
Sets the callback, which will be invoked before loop run. All previously set event listeners or callbacks are discarded.
event()
Returns XS::Framework::CallbackDispatcher instance, where callback(s) can be assigned with. The callbacks will be invoked before loop run.
The C++ interface is:
void(const PrepareSP&);
On perl side it the callbacks will be called :
$callback->($handle);
Multiple callbacks can be added via the XS::Framework::CallbackDispatcher interface.
event_listener($delegate [, $weak = false])
Creates and returns wrapper around the $delegate
object of arbitrary class, having the following methods:
$delegate->on_prepare($handle);
The delegated object can be seen as alternative of setting indivitual callbacks or as a way of groupping them. The $delegate
object can optionally be weakened.
call_now()
Immediately ivokes assigned callbacks and listeners in the caller context (i.e. not waiting loop run).
CONSTANTS
TYPE
Prepare type constant