asyncdispatch: formatting fixes
This commit is contained in:
parent
6bdd00db0e
commit
cb5b1c9344
3 changed files with 15 additions and 11 deletions
|
|
@ -192,7 +192,7 @@ proc adjustedTimeout(p: PDispatcherBase, timeout: int): int {.inline.} =
|
||||||
proc callSoon(cbproc: proc ()) {.gcsafe.}
|
proc callSoon(cbproc: proc ()) {.gcsafe.}
|
||||||
|
|
||||||
proc initCallSoonProc =
|
proc initCallSoonProc =
|
||||||
if asyncfutures.getCallSoonProc() == nil:
|
if asyncfutures.getCallSoonProc().isNil:
|
||||||
asyncfutures.setCallSoonProc(callSoon)
|
asyncfutures.setCallSoonProc(callSoon)
|
||||||
|
|
||||||
when defined(windows) or defined(nimdoc):
|
when defined(windows) or defined(nimdoc):
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ type
|
||||||
when not defined(release):
|
when not defined(release):
|
||||||
var currentID = 0
|
var currentID = 0
|
||||||
|
|
||||||
var callSoonProc {.threadvar.}: (proc(cbproc: proc ()) {.gcsafe.})
|
var callSoonProc {.threadvar.}: proc (cbproc: proc ()) {.gcsafe.}
|
||||||
|
|
||||||
proc getCallSoonProc*(): (proc(cbproc: proc ()) {.gcsafe.}) =
|
proc getCallSoonProc*(): (proc(cbproc: proc ()) {.gcsafe.}) =
|
||||||
## Get current implementation of ``callSoon``.
|
## Get current implementation of ``callSoon``.
|
||||||
|
|
@ -48,7 +48,7 @@ proc callSoon*(cbproc: proc ()) =
|
||||||
## If async dispatcher is running, ``cbproc`` will be executed during next dispatcher tick.
|
## If async dispatcher is running, ``cbproc`` will be executed during next dispatcher tick.
|
||||||
##
|
##
|
||||||
## If async dispatcher is not running, ``cbproc`` will be executed immediately.
|
## If async dispatcher is not running, ``cbproc`` will be executed immediately.
|
||||||
if callSoonProc == nil:
|
if callSoonProc.isNil:
|
||||||
# Loop not initialized yet. Call the function directly to allow setup code to use futures.
|
# Loop not initialized yet. Call the function directly to allow setup code to use futures.
|
||||||
cbproc()
|
cbproc()
|
||||||
else:
|
else:
|
||||||
|
|
@ -108,10 +108,10 @@ proc call(callbacks: var CallbackList) =
|
||||||
var current = callbacks
|
var current = callbacks
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
if current.function != nil:
|
if not current.function.isNil:
|
||||||
callSoon(current.function)
|
callSoon(current.function)
|
||||||
|
|
||||||
if current.next == nil:
|
if current.next.isNil:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
current = current.next[]
|
current = current.next[]
|
||||||
|
|
@ -121,7 +121,7 @@ proc call(callbacks: var CallbackList) =
|
||||||
callbacks.function = nil
|
callbacks.function = nil
|
||||||
|
|
||||||
proc add(callbacks: var CallbackList, function: CallbackFunc) =
|
proc add(callbacks: var CallbackList, function: CallbackFunc) =
|
||||||
if callbacks.function == nil:
|
if callbacks.function.isNil:
|
||||||
callbacks.function = function
|
callbacks.function = function
|
||||||
assert callbacks.next == nil
|
assert callbacks.next == nil
|
||||||
else:
|
else:
|
||||||
|
|
@ -154,7 +154,7 @@ proc complete*[T](future: FutureVar[T]) =
|
||||||
checkFinished(fut)
|
checkFinished(fut)
|
||||||
assert(fut.error == nil)
|
assert(fut.error == nil)
|
||||||
fut.finished = true
|
fut.finished = true
|
||||||
fut.callbacks.call
|
fut.callbacks.call()
|
||||||
|
|
||||||
proc complete*[T](future: FutureVar[T], val: T) =
|
proc complete*[T](future: FutureVar[T], val: T) =
|
||||||
## Completes a ``FutureVar`` with value ``val``.
|
## Completes a ``FutureVar`` with value ``val``.
|
||||||
|
|
@ -176,7 +176,7 @@ proc fail*[T](future: Future[T], error: ref Exception) =
|
||||||
future.error = error
|
future.error = error
|
||||||
future.errorStackTrace =
|
future.errorStackTrace =
|
||||||
if getStackTrace(error) == "": getStackTrace() else: getStackTrace(error)
|
if getStackTrace(error) == "": getStackTrace() else: getStackTrace(error)
|
||||||
future.callbacks.call
|
future.callbacks.call()
|
||||||
|
|
||||||
proc clearCallbacks(future: FutureBase) =
|
proc clearCallbacks(future: FutureBase) =
|
||||||
future.callbacks.function = nil
|
future.callbacks.function = nil
|
||||||
|
|
@ -192,11 +192,15 @@ proc addCallback*(future: FutureBase, cb: proc() {.closure,gcsafe.}) =
|
||||||
else:
|
else:
|
||||||
future.callbacks.add cb
|
future.callbacks.add cb
|
||||||
|
|
||||||
proc addCallback*[T](future: Future[T], cb: proc(future: Future[T]) {.closure,gcsafe.}) =
|
proc addCallback*[T](future: Future[T],
|
||||||
|
cb: proc (future: Future[T]) {.closure,gcsafe.}) =
|
||||||
## Adds the callbacks proc to be called when the future completes.
|
## Adds the callbacks proc to be called when the future completes.
|
||||||
##
|
##
|
||||||
## If future has already completed then ``cb`` will be called immediately.
|
## If future has already completed then ``cb`` will be called immediately.
|
||||||
future.addCallback proc() = cb(future)
|
future.addCallback(
|
||||||
|
proc() =
|
||||||
|
cb(future)
|
||||||
|
)
|
||||||
|
|
||||||
proc `callback=`*(future: FutureBase, cb: proc () {.closure,gcsafe.}) =
|
proc `callback=`*(future: FutureBase, cb: proc () {.closure,gcsafe.}) =
|
||||||
## Clears the list of callbacks and sets the callback proc to be called when the future completes.
|
## Clears the list of callbacks and sets the callback proc to be called when the future completes.
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,7 @@ proc adjustedTimeout(p: PDispatcherBase, timeout: int): int {.inline.} =
|
||||||
proc callSoon(cbproc: proc ()) {.gcsafe.}
|
proc callSoon(cbproc: proc ()) {.gcsafe.}
|
||||||
|
|
||||||
proc initCallSoonProc =
|
proc initCallSoonProc =
|
||||||
if asyncfutures.getCallSoonProc() == nil:
|
if asyncfutures.getCallSoonProc().isNil:
|
||||||
asyncfutures.setCallSoonProc(callSoon)
|
asyncfutures.setCallSoonProc(callSoon)
|
||||||
|
|
||||||
when defined(windows) or defined(nimdoc):
|
when defined(windows) or defined(nimdoc):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue