Skip to content

Commit f9cdfb4

Browse files
committed
Cancellation tests
1 parent eca66ce commit f9cdfb4

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

jvm/src/test/scala/CancellationBehavior.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import language.experimental.captureChecking
2+
13
import gears.async.AsyncOperations.*
24
import gears.async.default.given
35
import gears.async.{Async, AsyncSupport, Future, uninterruptible}

shared/src/main/scala/async/listeners/locking.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ case class ConflictingLocksException(
2727
def lockBoth[T, U](
2828
lt: Listener[T]^,
2929
lu: Listener[U]^
30-
): (lt.type | lu.type | true)^{lt, lu} =
30+
): (lt.type | lu.type | true) =
3131
val lockT = if lt.lock == null then return (if lu.acquireLock() then true else lu) else lt.lock
3232
val lockU = if lu.lock == null then return (if lt.acquireLock() then true else lt) else lu.lock
3333

3434
def doLock[T, U](lt: Listener[T]^, lu: Listener[U]^)(
3535
lockT: ListenerLock^{lt},
3636
lockU: ListenerLock^{lu}
37-
): (lt.type | lu.type | true)^{lt, lu} =
37+
): (lt.type | lu.type | true) =
3838
// assert(lockT.number > lockU.number)
3939
if !lockT.acquire() then lt
4040
else if !lockU.acquire() then

shared/src/test/scala/CancellationBehavior.scala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import language.experimental.captureChecking
2+
13
import gears.async.AsyncOperations.*
24
import gears.async.default.given
35
import gears.async.{Async, AsyncSupport, Future, uninterruptible}
@@ -12,9 +14,9 @@ import boundary.break
1214
class CancellationBehavior extends munit.FunSuite:
1315
enum State:
1416
case Ready
15-
case Initialized(f: Future[?])
17+
case Initialized
1618
case RunningEarly
17-
case Running(f: Future[?])
19+
case Running
1820
case Failed(t: Throwable)
1921
case Cancelled
2022
case Completed
@@ -27,19 +29,21 @@ class CancellationBehavior extends munit.FunSuite:
2729
state match
2830
case State.Ready =>
2931
state = State.RunningEarly
30-
case State.Initialized(f) =>
31-
state = State.Running(f)
32+
case State.Initialized =>
33+
state = State.Running
3234
case _ => fail(s"running failed, state is $state")
33-
def initialize(f: Future[?]) =
35+
def initialize(f: Future[?]^) =
3436
synchronized:
3537
state match
3638
case State.Ready =>
37-
state = State.Initialized(f)
39+
state = State.Initialized
3840
case State.RunningEarly =>
39-
state = State.Running(f)
41+
state = State.Running
4042
case _ => fail(s"initializing failed, state is $state")
4143

42-
private def startFuture(info: Info, body: Async ?=> Unit = {})(using a: Async, s: Async.Spawn & a.type) =
44+
private def startFuture(info: Info, body: Async ?=> Unit = {})(using a: Async, s: Async.Spawn)(using
45+
a.type =:= s.type
46+
) =
4347
val f = Future:
4448
info.run()
4549
try
@@ -67,7 +71,7 @@ class CancellationBehavior extends munit.FunSuite:
6771
test("group cancel"):
6872
var x = 0
6973
Async.blocking:
70-
Async.group:
74+
Async.group[Unit]:
7175
Future:
7276
sleep(400)
7377
x = 1

0 commit comments

Comments
 (0)