Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Callback multiplexer

by Dallaylaen (Pilgrim)
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2016-10-22 12:50 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (294 votes). Check out past polls.