Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a basic cancellation object.
  • Loading branch information
jnthn committed Apr 21, 2014
1 parent a38725d commit b4fcf26
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/core/Cancellation.pm
@@ -0,0 +1,21 @@
my class Cancellation {
has $.cancelled;
has $!lock;
has @!async_handles;

submethod BUILD(:@!async_handles) {
$!cancelled = False;
$!lock = Lock.new;
}

method cancel() {
$!lock.protect({
unless $!cancelled {
for @!async_handles {
nqp::cancel(nqp::decont($_));
}
$!cancelled = True;
}
})
}
}
1 change: 1 addition & 0 deletions tools/build/Makefile-Moar.in
Expand Up @@ -157,6 +157,7 @@ M_CORE_SOURCES = \
src/core/Thread.pm \
src/core/Lock.pm \
src/core/Semaphore.pm \
src/core/Cancellation.pm \
src/core/Scheduler.pm \
src/core/ThreadPoolScheduler.pm \
src/core/CurrentThreadScheduler.pm \
Expand Down

0 comments on commit b4fcf26

Please sign in to comment.