coro

Nim coroutines implementation, supports several context switching methods:

ucontextavailable on unix and alike (default)
setjmpavailable on unix and alike (x86/64 only)
fibersavailable and required on windows.
-d:nimCoroutinesRequired to build this module.
-d:nimCoroutinesUcontextUse ucontext backend.
-d:nimCoroutinesSetjmpUse setjmp backend.
-d:nimCoroutinesSetjmpBundledUse bundled setjmp implementation.

この API は不安定です。

Timer support for the realtime GC. Based on https://github.com/jckarter/clay/blob/master/compiler/hirestimer.cpp

CoroutineRef = ref object
  coro: CoroutinePtr
CoroutineRef holds a pointer to actual coroutine object. Public API always returns CoroutineRef instead of CoroutinePtr in order to allow holding a reference to coroutine object while it can be safely deallocated by coroutine scheduler loop. In this case Coroutine.reference.coro is set to nil. Public API checks for for it being nil and gracefully fails if it is nil.   ソース 編集

プロシージャ

proc suspend(sleepTime: float = 0) {...}{.raises: [], tags: [].}
Stops coroutine execution and resumes no sooner than after sleeptime seconds. Until then other coroutines are executed.   ソース 編集
proc start(c: proc (); stacksize: int = defaultStackSize): CoroutineRef {...}{.discardable,
    raises: [Exception], tags: [RootEffect].}
Schedule coroutine for execution. It does not run immediately.   ソース 編集
proc run() {...}{.raises: [], tags: [TimeEffect].}
Starts main coroutine scheduler loop which exits when all coroutines exit. Calling this proc starts execution of first coroutine.   ソース 編集
proc alive(c: CoroutineRef): bool {...}{.raises: [], tags: [].}
Returns true if coroutine has not returned, false otherwise.   ソース 編集
proc wait(c: CoroutineRef; interval = 0.01) {...}{.raises: [], tags: [].}
Returns only after coroutine c has returned. interval is time in seconds how often.   ソース 編集