Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make sending $index depend on arity of block
  • Loading branch information
lizmat committed Apr 20, 2014
1 parent 33ea6e5 commit 6e04fb6
Showing 1 changed file with 35 additions and 39 deletions.
74 changes: 35 additions & 39 deletions src/core/Supply.pm
Expand Up @@ -116,45 +116,41 @@ sub on(&setup) {
method !add_source(
$source, $lock, $index, :&more, :&done is copy, :&quit is copy
) {
unless defined &more {
X::Supply::On::NoMore.new.throw;
}
unless defined &done {
&done = { self.done }
}
unless defined &quit {
&quit = -> $ex { self.quit($ex) }
}
if $index.defined {
$source.tap(
-> \val {
$lock.protect({ more(val,$index) });
CATCH { default { self.quit($_) } }
},
done => {
$lock.protect({ done($index) });
CATCH { default { self.quit($_) } }
},
quit => -> $ex {
$lock.protect({ quit($ex,$index) });
CATCH { default { self.quit($_) } }
});
}
else {
$source.tap(
-> \val {
$lock.protect({ more(val) });
CATCH { default { self.quit($_) } }
},
done => {
$lock.protect({ done() });
CATCH { default { self.quit($_) } }
},
quit => -> $ex {
$lock.protect({ quit($ex) });
CATCH { default { self.quit($_) } }
});
}
&more // X::Supply::On::NoMore.new.throw;
&done //= { self.done };
&quit //= -> $ex { self.quit($ex) };

my &tap_more = &more.arity == 2
?? -> \val {
$lock.protect({ more(val,$index) });
CATCH { default { self.quit($_) } }
}
!! -> \val {
$lock.protect({ more(val) });
CATCH { default { self.quit($_) } }
};

my &tap_done = &done.arity == 2
?? {
$lock.protect({ done($index) });
CATCH { default { self.quit($_) } }
}
!! {
$lock.protect({ done() });
CATCH { default { self.quit($_) } }
};

my &tap_quit = &quit.arity == 2
?? -> $ex {
$lock.protect({ quit($ex,$index) });
CATCH { default { self.quit($_) } }
}
!! -> $ex {
$lock.protect({ quit($ex) });
CATCH { default { self.quit($_) } }
};

$source.tap( &tap_more, done => &tap_done, quit => &tap_quit );
}

method tap(|c) {
Expand Down

0 comments on commit 6e04fb6

Please sign in to comment.