NAME
Object::Deferred - A simple API for handling asynchronous events.
VERSION
version 0.001
SYNOPSIS
use Object::Deferred;
my $print = Object::Deferred->new;
my $hello = Object::Deferred->new;
my $world = Object::Deferred->new;
my $out = 'Not Enough Info Yet';
$print->then( sub { $out = join '', @_ } );
print $out, "\n";
$world->resolve('World');
print $out, "\n";
$world->then(
sub {
my $w = shift;
$hello->then(
sub {
my $h = shift;
$print->resolve("$h $w\n");
}
);
}
);
print $out, "\n";
$hello->resolve('Hello');
print $out, "\n";
DESCRIPTION
This is an implementation of the CommonJS promise API specification draft. It provides a clean way to create events and install hooks that run when those events are triggered.
ATTRIBUTES
resolution
An ArrayRef containing the resolution value for this deferred object. Returns undef if the object is in an unfulfilled state.
rejection
An ArrayRef containing the rejection value for this deferred object. Returns undef if the object is in an unfulfilled state.
METHODS
then
my $chain_deferred = $deferred->then(\&resolve, \&reject);
This method installs callbacks that run when the deferred object is resolved or rejected. If the object is an unfulfilled state, callback execution is deferred until the object is resolved or rejected. If the object has already been resolved or rejected, newly installed callbacks execute immediately taking the appropriate resolution or rejection values as a parameter.
resolve
Resolve a deferred object by passing it a resolution value. Resolution callbacks will be fired the first time this value is provided.
reject
Reject a deferred object by passing it a rejection value. Rejection callbacks will be fired the first time this value is provided.
AUTHOR
Eden Cardim <edencardim@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2011 by Eden Cardim <edencardim@gmail.com>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.