mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-13 06:43:52 +00:00
asyncdispatch: add callSoon getter/setter, renames
This commit is contained in:
@@ -191,9 +191,9 @@ proc adjustedTimeout(p: PDispatcherBase, timeout: int): int {.inline.} =
|
||||
|
||||
proc callSoon(cbproc: proc ()) {.gcsafe.}
|
||||
|
||||
proc initGlobalDispatcher =
|
||||
if asyncfutures.callSoonProc == nil:
|
||||
asyncfutures.callSoonProc = callSoon
|
||||
proc initCallSoonProc =
|
||||
if asyncfutures.getCallSoonProc() == nil:
|
||||
asyncfutures.setCallSoonProc(callSoon)
|
||||
|
||||
when defined(windows) or defined(nimdoc):
|
||||
import winlean, sets, hashes
|
||||
@@ -247,7 +247,7 @@ when defined(windows) or defined(nimdoc):
|
||||
if not gDisp.isNil:
|
||||
assert gDisp.callbacks.len == 0
|
||||
gDisp = disp
|
||||
initGlobalDispatcher()
|
||||
initCallSoonProc()
|
||||
|
||||
proc getGlobalDispatcher*(): PDispatcher =
|
||||
if gDisp.isNil:
|
||||
@@ -944,7 +944,7 @@ else:
|
||||
if not gDisp.isNil:
|
||||
assert gDisp.callbacks.len == 0
|
||||
gDisp = disp
|
||||
initGlobalDispatcher()
|
||||
initCallSoonProc()
|
||||
|
||||
proc getGlobalDispatcher*(): PDispatcher =
|
||||
if gDisp.isNil:
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
include "system/inclrtl"
|
||||
|
||||
import os, tables, strutils, times, heapqueue, options, deques
|
||||
|
||||
# TODO: This shouldn't need to be included, but should ideally be exported.
|
||||
@@ -34,9 +32,22 @@ type
|
||||
when not defined(release):
|
||||
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 ()) =
|
||||
## 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:
|
||||
# Loop not initialized yet. Call the function directly to allow setup code to use futures.
|
||||
cbproc()
|
||||
|
||||
@@ -163,9 +163,9 @@ proc adjustedTimeout(p: PDispatcherBase, timeout: int): int {.inline.} =
|
||||
|
||||
proc callSoon(cbproc: proc ()) {.gcsafe.}
|
||||
|
||||
proc initGlobalDispatcher =
|
||||
if asyncfutures.callSoonProc == nil:
|
||||
asyncfutures.callSoonProc = callSoon
|
||||
proc initCallSoonProc =
|
||||
if asyncfutures.getCallSoonProc() == nil:
|
||||
asyncfutures.setCallSoonProc(callSoon)
|
||||
|
||||
when defined(windows) or defined(nimdoc):
|
||||
import winlean, sets, hashes
|
||||
@@ -225,7 +225,7 @@ when defined(windows) or defined(nimdoc):
|
||||
if not gDisp.isNil:
|
||||
assert gDisp.callbacks.len == 0
|
||||
gDisp = disp
|
||||
initGlobalDispatcher()
|
||||
initCallSoonProc()
|
||||
|
||||
proc getGlobalDispatcher*(): PDispatcher =
|
||||
if gDisp.isNil:
|
||||
@@ -1094,7 +1094,7 @@ else:
|
||||
if not gDisp.isNil:
|
||||
assert gDisp.callbacks.len == 0
|
||||
gDisp = disp
|
||||
initGlobalDispatcher()
|
||||
initCallSoonProc()
|
||||
|
||||
proc getGlobalDispatcher*(): PDispatcher =
|
||||
if gDisp.isNil:
|
||||
|
||||
Reference in New Issue
Block a user