Skip to content

Commit

Permalink
Implement Publish.interval.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnthn committed Nov 2, 2013
1 parent 42f2a5f commit a58b135
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/vm/jvm/core/Threading.pm
Expand Up @@ -903,6 +903,29 @@ my class Publish {
}
ForSubscribable.new(:@values, :$scheduler)
}

method interval($interval, $delay = 0, :$scheduler = $*SCHEDULER) {
my class IntervalSubscribable does Subscribable {
has $!scheduler;
has $!interval;
has $!delay;

submethod BUILD(:$!scheduler, :$!interval, :$!delay) {}

method subscribe(|c) {
my $sub = self.Subscribable::subscribe(|c);
$!scheduler.schedule_every(
{
state $i = 0;
$sub.next().($i++);
},
$!interval, $!delay
);
$sub
}
}
IntervalSubscribable.new(:$interval, :$delay, :$scheduler)
}
}

# A KeyReducer provides a thread-safe way to compose a hash from multiple
Expand Down

0 comments on commit a58b135

Please sign in to comment.