Future::XS - experimental XS implementation of Future
Future::XS
Future
my $future = Future::XS->new; perform_some_operation( on_complete => sub { $future->done( @_ ); } ); $future->on_ready( sub { say "The operation is complete"; } );
This module provides an XS-based implementation of the Future class. It is currently experimental and shipped in its own distribution for testing purposes, though once it seems stable the plan is to move it into the main Future distribution and load it automatically in favour of the pureperl implementation on supported systems.
In a program not involving multiple threads, this module behaves entirely as expected, following the behaviour of the regular pure-perl Future implementation (regardless of whether or not the perl interpreter is actually built to support threads).
When multiple threads are created, previous versions of this module would most likely crash. The current version (0.10) fixes enough of the logic, that future instances that are only ever accessed from one thread (either the initial main thread, or any additional sidecar threads) will work fine. However, future instances cannot currently cross the boundary between threads. Any instances that were created before a new thread is made will no longer be accessible within that thread, and instances may not be returned as the result of the thread exit value. Some of these restrictions may be relaxed in later versions.
Attempts to access a future instance created in one thread from another thread will raise an exception:
Future::XS instance IO::Async::Future=SCALAR(0x...) is not available in this thread at ...
As a special case for process cleanup activities, the ->cancel method does not throw this exception, but simply returns silently. This is because cleanup code such as DESTROY methods or defer blocks often attempt to call this on existing instances.
->cancel
DESTROY
defer
Paul Evans <leonerd@leonerd.org.uk>
To install Future::XS, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Future::XS
CPAN shell
perl -MCPAN -e shell install Future::XS
For more information on module installation, please visit the detailed CPAN module installation guide.