-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from m8nmueller/vthread-schedule-abool
Use interruptGuard in VThreadScheduler
- Loading branch information
Showing
2 changed files
with
62 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import gears.async.{Async, Future, Listener} | ||
import gears.async.AsyncOperations.* | ||
import gears.async.default.given | ||
import concurrent.duration.DurationInt | ||
import gears.async.Future.Promise | ||
import scala.util.Success | ||
|
||
class SchedulerBehavior extends munit.FunSuite { | ||
test("schedule cancellation works") { | ||
Async.blocking: | ||
var bodyRan = false | ||
val cancellable = Async.current.scheduler.schedule(1.seconds, () => bodyRan = true) | ||
|
||
// cancel immediately | ||
cancellable.cancel() | ||
|
||
sleep(1000) | ||
assert(!bodyRan) | ||
} | ||
|
||
test("schedule cancellation doesn't abort inner code") { | ||
Async.blocking: | ||
var bodyRan = false | ||
val fut = Promise[Unit]() | ||
val cancellable = Async.current.scheduler.schedule( | ||
50.milliseconds, | ||
() => | ||
fut.complete(Success(())) | ||
Async.blocking: | ||
sleep(500) | ||
bodyRan = true | ||
) | ||
|
||
// cancel after body started running | ||
fut.await | ||
cancellable.cancel() | ||
|
||
sleep(1000) | ||
|
||
assert(bodyRan) | ||
} | ||
} |