Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: Callback multiplexer

by Dallaylaen (Monk)
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?

Comment on Re: Callback multiplexer
Download Code

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 avoiding work at the Monastery: (7)
As of 2016-02-12 06:09 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (388 votes), past polls