1. my class Cancellation {
  2. has $.cancelled;
  3. has $!lock;
  4. has @!async_handles;
  5. submethod BUILD(:@!async_handles --> Nil) {
  6. $!cancelled = False;
  7. $!lock = Lock.new;
  8. }
  9. method cancel() {
  10. $!lock.protect({
  11. unless $!cancelled {
  12. for @!async_handles {
  13. nqp::cancel(nqp::decont($_));
  14. }
  15. $!cancelled = True;
  16. }
  17. })
  18. }
  19. }