Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Callback multiplexer

by Dallaylaen (Hermit)
on Apr 05, 2013 at 07:32 UTC ( #1027088=note: print w/replies, xml ) Need Help??

in reply to Callback multiplexer

I'd like to be able to write something like this:
#!/usr/bin/perl -w use strict; use 5.010; use Some::Module; # Set goals my $cb = Some::Module->new( sub { say 'BOOM!' } ); $cb->begin( qw(foo bar) ); # Much later, as tasks start getting done $cb->end( foo => 42 ); # "return" value from task 'foo' $cb->begin( 'baz' ); # can add more tasks, why not $cb->end( 'bar' ); # just finish task 'bar' # still waiting for 'baz' to finish at this point # These shall not pass $cb->end( foo => 41 ); # not a second time $cb->end( food => 'bard' ); # we didn't expect that # Not fond of dying in async code, so probably # add some customizable error handler, # say $cb->on_error(sub {...}); or like that # Finally, last hanging task is done $cb->end( baz => 137 ); # BOOM! # at this point, sub {}->( { foo=>42, bar=>undef, baz=>137 } ) has bee +n called
Looks easy enough to implement, but maybe there's already something like that?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027088]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2018-05-27 18:45 GMT
Find Nodes?
    Voting Booth?