NAME
UniEvent::Idle - runs the given callback once per loop iteration
SYNOPSIS
my $loop = UniEvent::Loop->new;
my $h = UniEvent::Idle->new($loop);
$h->event->add(sub { say 'hello' });
$h->start;
$loop->run_nowait; # prints 'hello'
$loop->run; # prints 'hello' multiple times... don't do that
$h->stop;
$h->reset;
DESCRIPTION
The handlce causes invocation on added callback(s) to be invoked once per loop iteration, before preraing them for I/O.
Adding the handle to the event loop causes it the loop to perform a zero timeout poll instead of blocking for I/O. Generally it is rather CPU consuming, so you should have a reason to do that.
The handle is inherited from UniEvent::Handle.
METHOD
new([$loop = UniEvent::Loop->default_loop])
Constructs new Idle handle and binds it to the specified event loop
start([$callback = undef])
Starts the Idle handle, i.e. makes it active for the next even loop iteration. Optionally it adds the $callback
to the event listeners.
stop()
Stops the Idle handle, i.e. makes it inactive for the next event loop iteration.
callback($code)
Sets the callback, which will be invoked after 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 once per loop iteration before preparing other hanlders for I/O. The C++ interface is:
void(const IdleSP&);
i.e. the callback returns nothing and as an argument takes Idle handle itself.
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_idle($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
Idle type constant