Nim coroutines implementation supports several context switching methods: ucontext: available on unix and alike (default) setjmp: available on unix and alike (x86/64 only) Fibers: available and required on windows.
-d:nimCoroutines | Required to build this module. |
---|---|
-d:nimCoroutinesUcontext | Use ucontext backend. |
-d:nimCoroutinesSetjmp | Use setjmp backend. |
-d:nimCoroutinesSetjmpBundled Use bundled setjmp implementation. |
CoroutineRef = ref object coro: CoroutinePtr
proc suspend(sleepTime: float = 0) {...}{.raises: [], tags: [].}
sleeptime
seconds. Until then other coroutines are executed. proc start(c: proc (); stacksize: int = defaultStackSize): CoroutineRef {...}{.discardable, raises: [Exception], tags: [RootEffect].}
proc run() {...}{.raises: [Exception], tags: [TimeEffect].}
proc alive(c: CoroutineRef): bool {...}{.raises: [], tags: [].}
true
if coroutine has not returned, false
otherwise. proc wait(c: CoroutineRef; interval = 0.01) {...}{.raises: [], tags: [].}
c
has returned. interval
is time in seconds how often.
© 2006–2018 Andreas Rumpf
Licensed under the MIT License.
https://nim-lang.org/docs/coro.html