NAME
Future::AsyncAwait::Awaitable
- the interface required by Future::AsyncAwait
DESCRIPTION
This module documents the method interface required by Future::AsyncAwait
to operate on future instances returned by expressions invoked by the await
keyword, and returned by functions declared by async sub
. This information is largely of relevance to implementors of other module integrations, event systems, or similar. It is not necessary to make regular use of the syntax provided by the module when working with existing event systems.
CONSTRUCTORS
The following methods are expected to create new future instances. They make use of the class set by the prevailing future_class
import argument, if set, or default to Future
if not.
done
Generate a new immediate future that is successful. The future will already be ready and have the list of values set as its result.
$f = $CLASS->done( @results )
# $f->is_ready will be true
# $f->get will return @results
fail
Generate a new immediate future that is failed. The future will already be ready and invoking the "get" method will throw the given exception.
$f = $CLASS->fail( $message )
# $f->is_ready will be true
# $f->get will throw $message
INSTANCE METHODS
new
Generate a new pending future of the same type as an existing one, which is not modified by doing so.
$new_f = $f->new
If the instance has any fields that are required for successful operation (such as application-wide context or event system components) these ought to be copied. The method should not
done
Sets the success result of an existing still-pending future. It will only be invoked on future instances that are currently pending.
$f->done( @results )
# $f->is_ready will now be true
# $f->get will now return @results
fail
Sets the failure result of an existing still-pending future. It will only be invoked on future instances that are currently pending.
$f->fail( $message )
# $f->is_ready will now be true
# $f->get will now throw $message
is_ready
Returns true if a future is ready (successful, failed or cancelled); false if still pending.
$bool = $f->is_ready
is_cancelled
Returns true is a future has already been cancelled; false if still pending, successful or failed.
$bool = $f->is_cancelled
get
Yields the result of a successful future (or just the first value if called in scalar context). Throws the failure message as an exception if called on a a failed one. Will not be invoked on a pending or cancelled future.
@result = $f->get
$result = $f->get
$f->get
on_ready
Attach a new CODE reference to be invoked when the future becomes ready (by success or failure). The arguments and context that $code
is invoked with are unspecified.
$f->on_ready( $code )
on_cancel
Attach a new CODE reference to be invoked when the future is cancelled. The arguments and context that $code
is invoked with are unspecified.
$f1->on_cancel( $f2 )
AUTHOR
Paul Evans <leonerd@leonerd.org.uk>