Skip to content

Commit

Permalink
.tap now has done/quit named parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Nov 23, 2013
1 parent b6eee1f commit ea77e4f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 31 deletions.
34 changes: 16 additions & 18 deletions src/vm/jvm/core/Supply.pm
Expand Up @@ -18,7 +18,7 @@ my role Supply {
has @!tappers;
has $!tappers_lock = Lock.new;

method tap(&more, &done?, &quit?) {
method tap(&more, :&done, :&quit) {
my $sub = Tap.new(:&more, :&done, :&quit, :supply(self));
$!tappers_lock.protect({
@!tappers.push($sub);
Expand Down Expand Up @@ -64,10 +64,9 @@ my role Supply {

method Channel() {
my $c = Channel.new();
self.tap(
-> \val { $c.send(val) },
{ $c.close },
-> $ex { $c.quit($ex) });
self.tap( -> \val { $c.send(val) },
done => { $c.close },
quit => -> $ex { $c.quit($ex) });
$c
}

Expand Down Expand Up @@ -126,19 +125,18 @@ sub on(&setup) {
&quit = -> $ex { self.quit($ex) }
}
$source.tap(
-> \val {
$lock.protect({ more(val) });
CATCH { self.quit($_) }
},
{
$lock.protect({ done() });
CATCH { self.quit($_) }
},
-> $ex {
$lock.protect({ quit($ex) });
CATCH { self.quit($_) }
}
);
-> \val {
$lock.protect({ more(val) });
CATCH { self.quit($_) }
},
done => {
$lock.protect({ done() });
CATCH { self.quit($_) }
},
quit => -> $ex {
$lock.protect({ quit($ex) });
CATCH { self.quit($_) }
});
}

method tap(|c) {
Expand Down
23 changes: 10 additions & 13 deletions src/vm/jvm/core/SupplyOperations.pm
Expand Up @@ -90,12 +90,11 @@ my class SupplyOperations is repr('Uninstantiable') {

method tap(|c) {
my $sub = self.Supply::tap(|c);
my $tap = $!source.tap(
-> \val {
if (&!filter(val)) { self!more(val) }
},
{ self!done(); },
-> $ex { self!quit($ex) }
my $tap = $!source.tap( -> \val {
if (&!filter(val)) { self!more(val) }
},
done => { self!done(); },
quit => -> $ex { self!quit($ex) }
);
$sub
}
Expand All @@ -112,13 +111,11 @@ my class SupplyOperations is repr('Uninstantiable') {

method tap(|c) {
my $sub = self.Supply::tap(|c);
my $tap = $!source.tap(
-> \val {
self!more(&!mapper(val))
},
{ self!done(); },
-> $ex { self!quit($ex) }
);
my $tap = $!source.tap( -> \val {
self!more(&!mapper(val))
},
done => { self!done(); },
quit => -> $ex { self!quit($ex) });
$sub
}
}
Expand Down

0 comments on commit ea77e4f

Please sign in to comment.