asyncdispatch: add callSoon getter/setter, renames
This commit is contained in:
parent
797690ba3f
commit
6bdd00db0e
3 changed files with 24 additions and 13 deletions
|
|
@ -191,9 +191,9 @@ proc adjustedTimeout(p: PDispatcherBase, timeout: int): int {.inline.} =
|
||||||
|
|
||||||
proc callSoon(cbproc: proc ()) {.gcsafe.}
|
proc callSoon(cbproc: proc ()) {.gcsafe.}
|
||||||
|
|
||||||
proc initGlobalDispatcher =
|
proc initCallSoonProc =
|
||||||
if asyncfutures.callSoonProc == nil:
|
if asyncfutures.getCallSoonProc() == nil:
|
||||||
asyncfutures.callSoonProc = callSoon
|
asyncfutures.setCallSoonProc(callSoon)
|
||||||
|
|
||||||
when defined(windows) or defined(nimdoc):
|
when defined(windows) or defined(nimdoc):
|
||||||
import winlean, sets, hashes
|
import winlean, sets, hashes
|
||||||
|
|
@ -247,7 +247,7 @@ when defined(windows) or defined(nimdoc):
|
||||||
if not gDisp.isNil:
|
if not gDisp.isNil:
|
||||||
assert gDisp.callbacks.len == 0
|
assert gDisp.callbacks.len == 0
|
||||||
gDisp = disp
|
gDisp = disp
|
||||||
initGlobalDispatcher()
|
initCallSoonProc()
|
||||||
|
|
||||||
proc getGlobalDispatcher*(): PDispatcher =
|
proc getGlobalDispatcher*(): PDispatcher =
|
||||||
if gDisp.isNil:
|
if gDisp.isNil:
|
||||||
|
|
@ -944,7 +944,7 @@ else:
|
||||||
if not gDisp.isNil:
|
if not gDisp.isNil:
|
||||||
assert gDisp.callbacks.len == 0
|
assert gDisp.callbacks.len == 0
|
||||||
gDisp = disp
|
gDisp = disp
|
||||||
initGlobalDispatcher()
|
initCallSoonProc()
|
||||||
|
|
||||||
proc getGlobalDispatcher*(): PDispatcher =
|
proc getGlobalDispatcher*(): PDispatcher =
|
||||||
if gDisp.isNil:
|
if gDisp.isNil:
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
include "system/inclrtl"
|
|
||||||
|
|
||||||
import os, tables, strutils, times, heapqueue, options, deques
|
import os, tables, strutils, times, heapqueue, options, deques
|
||||||
|
|
||||||
# TODO: This shouldn't need to be included, but should ideally be exported.
|
# TODO: This shouldn't need to be included, but should ideally be exported.
|
||||||
|
|
@ -34,9 +32,22 @@ 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.}) =
|
||||||
|
## Get current implementation of ``callSoon``.
|
||||||
|
return callSoonProc
|
||||||
|
|
||||||
|
proc setCallSoonProc*(p: (proc(cbproc: proc ()) {.gcsafe.})) =
|
||||||
|
## Change current implementation of ``callSoon``. This is normally called when dispatcher from ``asyncdispatcher`` is initialized.
|
||||||
|
callSoonProc = p
|
||||||
|
|
||||||
proc callSoon*(cbproc: proc ()) =
|
proc callSoon*(cbproc: proc ()) =
|
||||||
|
## Call ``cbproc`` "soon".
|
||||||
|
##
|
||||||
|
## 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 callSoonProc == nil:
|
if callSoonProc == nil:
|
||||||
# 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()
|
||||||
|
|
|
||||||
|
|
@ -163,9 +163,9 @@ proc adjustedTimeout(p: PDispatcherBase, timeout: int): int {.inline.} =
|
||||||
|
|
||||||
proc callSoon(cbproc: proc ()) {.gcsafe.}
|
proc callSoon(cbproc: proc ()) {.gcsafe.}
|
||||||
|
|
||||||
proc initGlobalDispatcher =
|
proc initCallSoonProc =
|
||||||
if asyncfutures.callSoonProc == nil:
|
if asyncfutures.getCallSoonProc() == nil:
|
||||||
asyncfutures.callSoonProc = callSoon
|
asyncfutures.setCallSoonProc(callSoon)
|
||||||
|
|
||||||
when defined(windows) or defined(nimdoc):
|
when defined(windows) or defined(nimdoc):
|
||||||
import winlean, sets, hashes
|
import winlean, sets, hashes
|
||||||
|
|
@ -225,7 +225,7 @@ when defined(windows) or defined(nimdoc):
|
||||||
if not gDisp.isNil:
|
if not gDisp.isNil:
|
||||||
assert gDisp.callbacks.len == 0
|
assert gDisp.callbacks.len == 0
|
||||||
gDisp = disp
|
gDisp = disp
|
||||||
initGlobalDispatcher()
|
initCallSoonProc()
|
||||||
|
|
||||||
proc getGlobalDispatcher*(): PDispatcher =
|
proc getGlobalDispatcher*(): PDispatcher =
|
||||||
if gDisp.isNil:
|
if gDisp.isNil:
|
||||||
|
|
@ -1094,7 +1094,7 @@ else:
|
||||||
if not gDisp.isNil:
|
if not gDisp.isNil:
|
||||||
assert gDisp.callbacks.len == 0
|
assert gDisp.callbacks.len == 0
|
||||||
gDisp = disp
|
gDisp = disp
|
||||||
initGlobalDispatcher()
|
initCallSoonProc()
|
||||||
|
|
||||||
proc getGlobalDispatcher*(): PDispatcher =
|
proc getGlobalDispatcher*(): PDispatcher =
|
||||||
if gDisp.isNil:
|
if gDisp.isNil:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue