Manpage logo

Future::Mojo - use Future with Mojo::IOLoop

NAME  SYNOPSIS  DESCRIPTION  CONSTRUCTORS  new  new_timer  new_timeout  METHODS  loop  await  done_next_tick  fail_next_tick  promisify  BUGS  AUTHOR  CONTRIBUTORS  COPYRIGHT AND LICENSE  SEE ALSO 

NAME

Future::Mojo − use Future with Mojo::IOLoop

SYNOPSIS

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";

DESCRIPTION

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.

CONSTRUCTORS

new

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.

new_timer

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.

new_timeout

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.

METHODS

Future::Mojo inherits all methods from Future and implements the following new ones.

loop

$loop = $future−>loop;

Returns the underlying Mojo::IOLoop object.

await

$future−>await;

Runs the underlying Mojo::IOLoop until the future is ready. If the event loop is already running, an exception is thrown.

done_next_tick

$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.

fail_next_tick

$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.

promisify

my $promise = $future−>promisify;

Composed from Future::Role::Promisify.

BUGS

Report any issues on the public bugtracker.

AUTHOR

Dan Book <[email protected]>

CONTRIBUTORS

Jose Luis Martinez (pplu)

COPYRIGHT AND LICENSE

This software is Copyright (c) 2015 by Dan Book.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)

SEE ALSO

Future


Updated 2026-06-01 - jenkler.se | uex.se