AnyEvent-Future

 view release on metacpan or  search on metacpan

MANIFEST  view on Meta::CPAN

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Build.PL
Changes
examples/http_get.pl
lib/AnyEvent/Future.pm
MANIFEST                        This list of files
t/00use.t
t/01anyevent.t
t/02timer.t
t/03condvar.t
t/99pod.t
README
LICENSE
META.yml
META.json

README  view on Meta::CPAN

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
new_delay
 
      $f = AnyEvent::Future->new_delay( @args )
 
new_timeout
 
      $f = AnyEvent::Future->new_timeout( @args )
 
   Returns a new leaf future instance that will become ready at the time
   given by the arguments, which will be passed to the AnyEvent->timer
   method.
 
   new_delay returns a future that will complete successfully at the
   alotted time, whereas new_timeout returns a future that will fail with
   the message Timeout. This is provided as a simple utility for small
   use-cases; for a more find-grained control over the failure message and
   additional values you may wish to use new_delay combined with the
   then_fail method:
 
      new_delay( after => 10 )

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

78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
=head2 new_delay
 
   $f = AnyEvent::Future->new_delay( @args )
 
=head2 new_timeout
 
   $f = AnyEvent::Future->new_timeout( @args )
 
Returns a new leaf future instance that will become ready at the time given by
the arguments, which will be passed to the C<< AnyEvent->timer >> method.
 
C<new_delay> returns a future that will complete successfully at the alotted
time, whereas C<new_timeout> returns a future that will fail with the message
C<Timeout>. This is provided as a simple utility for small use-cases; for a
more find-grained control over the failure message and additional values you
may wish to use C<new_delay> combined with the C<then_fail> method:
 
   new_delay( after => 10 )
      ->then_fail( "The operation timed out after 10 seconds", timeout => );
 
=cut
 
sub new_delay
{
   shift;
   my %args = @_;
 
   as_future {
      my $f = shift;
      AnyEvent->timer( %args, cb => sub { $f->done } );
   };
}
 
sub new_timeout
{
   shift;
   my %args = @_;
 
   as_future {
      my $f = shift;
      AnyEvent->timer( %args, cb => sub { $f->fail( "Timeout" ) } );
   };
}
 
=head2 from_cv
 
   $f = AnyEvent::Future->from_cv( $cv )
 
Returns a new leaf future instance that will become ready when the given
L<AnyEvent::CondVar> instance is ready. The success or failure result of the
future will be the result passed to the condvar's C<send> or C<croak> method.

t/01anyevent.t  view on Meta::CPAN

24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
   };
 
   is_deeply( [ $future->get ], [ "another result" ], '$future->get on as_future' );
}
 
# as_future cancellation
{
   my $called;
   my $future = as_future {
      my $f = shift;
      return AnyEvent->timer(
         after => 0.01,
         cb => sub { $called++; $f->done; },
      );
   };
 
   $future->cancel;
 
   my $cv = AnyEvent->condvar;
   my $tmp = AnyEvent->timer( after => 0.03, cb => sub { $cv->send } );
   $cv->recv;
 
   ok( !$called, '$future->cancel cancels a pending watch' );
}
 
# as_future_cb done
{
   my $future = as_future_cb {
      my ( $done ) = @_;
      AnyEvent::postpone { $done->( "success" ) };



( run in 0.445 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )