Skip to content

Instantly share code, notes, and snippets.

@MattRix
Created April 21, 2023 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MattRix/5de71ae6ae1ffdf814978a9a752eed8e to your computer and use it in GitHub Desktop.
Save MattRix/5de71ae6ae1ffdf814978a9a752eed8e to your computer and use it in GitHub Desktop.
Cancelable Coroutines with Verse (using race)
<#> 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