Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/grinnz/future-mojo

Future::Mojo - use Future with Mojo::IOLoop
https://github.com/grinnz/future-mojo

Last synced: about 2 months ago
JSON representation

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

Awesome Lists containing this project

README

        

=pod

=head1 NAME

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

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

=head1 DESCRIPTION

This subclass of L stores a reference to the associated L
instance, allowing the C method to block until the Future is ready.

For a full description on how to use Futures, see the L documentation.

=head1 CONSTRUCTORS

=head2 new

my $future = Future::Mojo->new;
my $future = Future::Mojo->new($loop);

Returns a new Future. Uses L if no loop is specified.

=head2 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
L if no loop is specified.

=head2 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
L if no loop is specified.

=head1 METHODS

L inherits all methods from L and implements the
following new ones.

=head2 loop

$loop = $future->loop;

Returns the underlying L object.

=head2 await

$future->await;

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

=head2 done_next_tick

$future = $future->done_next_tick(@result);

A shortcut to calling the L method on the
L. Ensures that a returned Future object is not ready
immediately, but will wait for the next I/O round.

=head2 fail_next_tick

$future = $future->fail_next_tick($exception, @details);

A shortcut to calling the L method on the
L. Ensures that a returned Future object is not ready
immediately, but will wait for the next I/O round.

=head2 promisify

my $promise = $future->promisify;

Composed from L.

=head1 BUGS

Report any issues on the public bugtracker.

=head1 AUTHOR

Dan Book

=head1 CONTRIBUTORS

=over

=item Jose Luis Martinez (pplu)

=back

=head1 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)

=head1 SEE ALSO

L

=cut