Types
Future[T] = ref object of FutureBase ## Stored value
- Typed future. Source Edit
FutureBase = ref object of RootObj error*: ref Exception ## Stored exception errorStackTrace*: string when not defined(release) or defined(futureLogging): ## For debugging purposes only.
- Untyped future. Source Edit
FutureError = object of Defect cause*: FutureBase
- Source Edit
Consts
isFutureLoggingEnabled = false
- Source Edit
NimAsyncContinueSuffix = "NimAsyncContinue"
- For internal usage. Do not use. Source Edit
Procs
proc addCallback(future: FutureBase; cb: proc () {.closure, ...gcsafe.}) {. ...raises: [Exception], tags: [RootEffect], forbids: [].}
-
Adds the callbacks proc to be called when the future completes.
If future has already completed then cb will be called immediately.
Source Edit proc addCallback[T](future: Future[T]; cb: proc (future: Future[T]) {.closure, ...gcsafe.})
-
Adds the callbacks proc to be called when the future completes.
If future has already completed then cb will be called immediately.
Source Edit proc all[T](futs: varargs[Future[T]]): auto
-
Returns a future which will complete once all futures in futs complete. If the argument is empty, the returned future completes immediately.
If the awaited futures are not Future[void], the returned future will hold the values of all awaited futures in a sequence.
If the awaited futures are Future[void], this proc returns Future[void].
Source Edit proc asyncCheck[T](future: Future[T])
-
Sets a callback on future which raises an exception if the future finished with an error.
This should be used instead of discard to discard void futures, or use waitFor if you need to wait for the future's completion.
Source Edit proc callback=(future: FutureBase; cb: proc () {.closure, ...gcsafe.}) {. ...raises: [Exception], tags: [RootEffect], forbids: [].}
-
Clears the list of callbacks and sets the callback proc to be called when the future completes.
If future has already completed then cb will be called immediately.
It's recommended to use addCallback or then instead.
Source Edit proc clearCallbacks(future: FutureBase) {....raises: [], tags: [], forbids: [].}
- Source Edit
proc failed(future: FutureBase): bool {....raises: [], tags: [], forbids: [].}
- Determines whether future completed with an error. Source Edit
proc getCallSoonProc(): (proc (cbproc: proc ()) {....gcsafe.}) {....raises: [], tags: [], forbids: [].}
- Get current implementation of callSoon. Source Edit
proc newFutureVar[T](fromProc = "unspecified"): owned(FutureVar[T])
-
Create a new FutureVar. This Future type is ideally suited for situations where you want to avoid unnecessary allocations of Futures.
Specifying fromProc, which is a string specifying the name of the proc that this future belongs to, is a good habit as it helps with debugging.
Source Edit proc setCallSoonProc(p: (proc (cbproc: proc ()) {....gcsafe.})) {....raises: [], tags: [], forbids: [].}
- Change current implementation of callSoon. This is normally called when dispatcher from asyncdispatcher is initialized. Source Edit