Advertisement
DRVTiny

ae_run_f.pl

Mar 16th, 2020
1,039
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.79 KB | None | 0 0
  1. sub ae_run_seq {
  2.     my $cv = AE::cv;
  3.     my $continue_cb =
  4.         ( is_refref($_[$#_]) and is_coderef(${$_[$#_]}) )
  5.             ? ${pop @_}
  6.             : sub { $_[0]->send };
  7.     my @callbacks = @_;
  8.     sub {
  9.         my $cb = scalar(shift @callbacks);
  10.         unless (! @callbacks or is_coderef($cb) ) {
  11.             die 'all callbacks must be code references'
  12.         }
  13.         $cb and $cb->($cv, __SUB__) or $continue_cb->($cv)
  14.     }->();
  15.     $cv->recv;
  16. }
  17.  
  18. sub ae_run_conc {
  19.     my $cv = AE::cv;
  20.     my $continue_cb = ( is_refref($_[$#_]) and is_coderef(${$_[$#_]}) ) ? ${pop @_} : undef;
  21.     my $auto_end = sub { $cv->end };
  22.     for my $callback ( @_ ) {
  23.         $cv->begin;
  24.         $callback->($cv, $auto_end);
  25.     }
  26.     $continue_cb and $continue_cb->($cv) or $cv->recv;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement