AnyEvent-Promise

 view release on metacpan or  search on metacpan

Build.PL  view on Meta::CPAN

    dist_version_from => 'lib/AnyEvent/Promise.pm',
    release_status => 'stable',
    configure_requires => {
        'Module::Build' => 0,
    },
    build_requires => {
        'Test::More' => 0,
    },
    requires => {
        'AnyEvent' => 0,
        'Try::Tiny' => 0,
        'Carp' => 0
    },
    add_to_cleanup => [ 'AnyEvent-Promise-*' ],
    create_makefile_pl => 'traditional',
);

$builder->create_build_script();

META.json  view on Meta::CPAN

      },
      "configure" : {
         "requires" : {
            "Module::Build" : "0"
         }
      },
      "runtime" : {
         "requires" : {
            "AnyEvent" : "0",
            "Carp" : "0",
            "Try::Tiny" : "0"
         }
      }
   },
   "provides" : {
      "AnyEvent::Promise" : {
         "file" : "lib/AnyEvent/Promise.pm",
         "version" : "0.02"
      }
   },
   "release_status" : "stable",

META.yml  view on Meta::CPAN

  url: http://module-build.sourceforge.net/META-spec-v1.4.html
  version: 1.4
name: AnyEvent-Promise
provides:
  AnyEvent::Promise:
    file: lib/AnyEvent/Promise.pm
    version: 0.02
requires:
  AnyEvent: 0
  Carp: 0
  Try::Tiny: 0
resources:
  license: http://opensource.org/licenses/mit-license.php
version: 0.02

Makefile.PL  view on Meta::CPAN

# Note: this file was auto-generated by Module::Build::Compat version 0.4007
use ExtUtils::MakeMaker;
WriteMakefile
(
  'PL_FILES' => {},
  'INSTALLDIRS' => 'site',
  'NAME' => 'AnyEvent::Promise',
  'EXE_FILES' => [],
  'VERSION_FROM' => 'lib/AnyEvent/Promise.pm',
  'PREREQ_PM' => {
                   'Try::Tiny' => 0,
                   'Test::More' => 0,
                   'AnyEvent' => 0,
                   'Carp' => 0
                 }
)
;

lib/AnyEvent/Promise.pm  view on Meta::CPAN

package AnyEvent::Promise;

use 5.008;
use strict;
use warnings FATAL => 'all';

use AnyEvent;
use Try::Tiny qw//;
use Carp;

=head1 NAME

AnyEvent::Promise - Evented promises

=head1 VERSION

Version 0.01

lib/AnyEvent/Promise.pm  view on Meta::CPAN

    $self->{guard}->begin;

    my $cvin = $self->{fulfill};
    if (!defined $cvin) {
        $cvin = $self->{initial};
    }

    my $cvout = AnyEvent->condvar;
    $cvin->cb(sub {
        my $thenret = shift;
        Try::Tiny::try {
            my $ret = $thenret->recv;
            my $cvret = $fn->($ret);
            if ($cvret and ref $cvret eq 'AnyEvent::CondVar') {
                $cvret->cb(sub {
                    my $ret_inner = shift;
                    Try::Tiny::try {
                        $cvout->send($ret_inner->recv);
                        $self->{guard}->end;
                    }
                    Try::Tiny::catch {
                        $self->{rejected} = 1;
                        $self->{reject}->send(@_);
                    }
                });
            }
            else {
                $cvout->send($cvret);
                $self->{guard}->end;
            }
        }
        Try::Tiny::catch {
            $self->{rejected} = 1;
            $self->{reject}->send(@_);
        }
    });
    $self->{fulfill} = $cvout;

    return $self;
}

=head2 catch($cb)

Catch raised errors in the callback chain. Exceptions in the promise chain will
jump up to this catch callback, bypassing any other callbacks in the promise
chain. The error caught by L<Try::Tiny> will be sent as arguments to the
callback C<$cb>.

=cut
sub catch {
    my ($self, $fn) = @_;

    $self->{reject}->cb(sub {
        my @err = shift->recv;
        $fn->(@err);
        $self->{guard}->send;



( run in 0.288 second using v1.01-cache-2.11-cpan-05444aca049 )