; Inside a shield cancellation is not observed: the shielded receive waits for ; the value; after the shield ends, task.check_cancel sees the pending request. ; expect: run ; grant: heap=mem.alloc:64 ; schedules: 20 ; result: 105 ; phase: 3 ; spec: docs/spec/04-concurrency-and-atomics.md module test.cancel_shield air 0 lang 0.1 features [cancellation, capabilities, channels, effects, heap, ownership, resources, tasks] fn @main(%heap: cap) -> u64 effects [mem.alloc, task.spawn, task.wait] entry: %one = const.usize 1 channel.make u64, %one, %heap, ok -> @made, err -> @oom made(%tx: sender, %rx: receiver): %sc = task.scope.begin %t = task.spawn %sc, @waiter(%rx) task.cancel %t %txb = borrow.mut %tx %five = const.u64 5 channel.send %txb, %five, ok -> @sent, closed -> @back, cancelled -> @back back(%w: u64): br @sent() sent: borrow.end %txb %r = task.join %t task.scope.end %sc channel.close_sender %tx ret %r oom(%e: alloc_error): trap fn @waiter(%rx: receiver) -> u64 effects [task.wait] entry: %sh = task.shield.begin %rb = borrow.mut %rx channel.recv %rb, ok -> @got, closed -> @bad, cancelled -> @bad got(%v: u64): borrow.end %rb task.shield.end %sh channel.close_receiver %rx, ok -> @check, pending -> @pending check: task.check_cancel, ok -> @plain, cancelled -> @seen plain: ret %v seen: %hundred = const.u64 100 %r = add.checked.u64 %v, %hundred ret %r bad: trap pending(%r2: receiver): trap