Future::Mojo - use Future with Mojo::IOLoop
use Future::Mojo;
use Mojo::IOLoop;
my $loop = Mojo::IOLoop->new;
my $future = Future::Mojo->new($loop);
$loop->timer(3 => sub { $future->done('Done') });
print $future->get, "\n";
This subclass of Future stores a reference to the associated Mojo::IOLoop instance, allowing the await
method to block until the Future is ready.
For a full description on how to use Futures, see the Future documentation.
my $future = Future::Mojo->new;
my $future = Future::Mojo->new($loop);
Returns a new Future. Uses "singleton" in Mojo::IOLoop if no loop is specified.
my $future = Future::Mojo->new_timer($seconds);
my $future = Future::Mojo->new_timer($loop, $seconds);
Returns a new Future that will become ready after the specified delay. Uses "singleton" in Mojo::IOLoop if no loop is specified.
my $future = Future::Mojo->new_timeout($seconds);
my $future = Future::Mojo->new_timeout($loop, $seconds);
Returns a new Future that will fail after the specified delay. Uses "singleton" in Mojo::IOLoop if no loop is specified.
Future::Mojo inherits all methods from Future and implements the following new ones.
$loop = $future->loop;
Returns the underlying Mojo::IOLoop object.
$future->await;
Runs the underlying Mojo::IOLoop until the future is ready. If the event loop is already running, an exception is thrown.
$future = $future->done_next_tick(@result);
A shortcut to calling the "done" in Future method on the "next_tick" in Mojo::IOLoop. Ensures that a returned Future object is not ready immediately, but will wait for the next I/O round.
$future = $future->fail_next_tick($exception, @details);
A shortcut to calling the "fail" in Future method on the "next_tick" in Mojo::IOLoop. Ensures that a returned Future object is not ready immediately, but will wait for the next I/O round.
my $promise = $future->promisify;
Composed from Future::Role::Promisify.
Report any issues on the public bugtracker.
Dan Book <dbook@cpan.org>
- Jose Luis Martinez (pplu)
This software is Copyright (c) 2015 by Dan Book.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)