Created
April 21, 2023 16:19
-
-
Save MattRix/5de71ae6ae1ffdf814978a9a752eed8e to your computer and use it in GitHub Desktop.
Cancelable Coroutines with Verse (using race)
This file contains hidden or 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
<#> Usage | |
Routine := SpawnRoutine(SomeLongTask) | |
Routine.Cancel() | |
SpawnRoutine(Func : type{_()<suspends>:void}):routine = | |
Routine := routine{Func := Func} | |
Routine.Start() | |
return Routine | |
routine := class(): | |
Event : event() = event(){} | |
Func : type{_()<suspends>:void} | |
Start():void = | |
spawn { RunRoutine() } | |
RunRoutine()<suspends>: void = | |
race: | |
Func() | |
Event.Await() | |
Cancel():void = | |
Event.Signal() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment