Skip to content

Instantly share code, notes, and snippets.

Created June 10, 2014 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/1606248d28b4f1430e88 to your computer and use it in GitHub Desktop.
Save anonymous/1606248d28b4f1430e88 to your computer and use it in GitHub Desktop.
class Foo {
has ThreadPoolScheduler $!scheduler = ThreadPoolScheduler.new;
has Channel $.c = Channel.new;
has Thread $.t;
method push ($any) {
$!c.send($any);
}
method BUILD {
say "run";
my $stop;
$!scheduler = ThreadPoolScheduler.new;
$!scheduler.cue(
:every(0),
:catch{$stop},
{
say "start";
loop {
my $msg = $!c.receive;
note "Got $msg";
note "Got $msg still";
last if $msg == 3;
}
say "stop";
},
);
say "...ning";
}
}
my $a = Foo.new;
#$a.run;
say "Sleep";
$a.push(7);
sleep 1;
$a.push(3);
say "pushed";
sleep 2;
say "die";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment