Skip to content

Commit

Permalink
Implement schedule_on.
Browse files Browse the repository at this point in the history
This allows a supply's more/done/quit to be scheduled on another
scheduler. Useful in GUI situations, for example, where the final
stage of some work needs to be done on some UI scheduler in order to
have UI updates run on the UI thread.
  • Loading branch information
jnthn committed Apr 23, 2014
1 parent d2dfb68 commit 631f02e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/Supply.pm
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ my role Supply {
method batch( :$elems, :$seconds ) {
SupplyOperations.batch( self, :$elems, :$seconds)
}
method schedule_on(Scheduler $scheduler) {
SupplyOperations.schedule_on(self, $scheduler);
}
method merge(*@s) { SupplyOperations.merge(self, @s) }
method zip(*@s,:&with) { SupplyOperations.zip(self, @s, :&with) }

Expand Down
21 changes: 21 additions & 0 deletions src/core/SupplyOperations.pm
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,27 @@ my class SupplyOperations is repr('Uninstantiable') {
}
BatchSupply.new(:source($s), :$elems, :$seconds)
}

method schedule_on(Supply $s, Scheduler $scheduler) {
my class ScheduleSupply does Supply does PrivatePublishing {
has $!source;
has $!scheduler;

submethod BUILD(:$!source, :$!scheduler) { }

method tap(|c) {
my $source_tap;
my $sub = self.Supply::tap(|c, closing => { $source_tap.close() });
$source_tap = $!source.tap( -> \val {
$!scheduler.cue: { self!more(val) }
},
done => { $!scheduler.cue: { self!done(); } },
quit => -> $ex { $!scheduler.cue: { self!quit($ex) } });
$sub
}
}
ScheduleSupply.new(:source($s), :$scheduler)
}

method merge(*@s) {

Expand Down

0 comments on commit 631f02e

Please sign in to comment.