mirror of
https://github.com/status-im/nim-chronos.git
synced 2025-02-21 15:38:20 +00:00
work around overload resolution issues (#146)
it seems that due to a naming conflict from asyncdispatch, callSoon is deduced to raise exceptions even if it doesn't in modules that import both, even indirectly - this patch randomly works around the issue with some more overloads
This commit is contained in:
parent
0933feaa35
commit
9a420c6b05
@ -218,7 +218,7 @@ proc finish(fut: FutureBase, state: FutureState) =
|
|||||||
fut.cancelcb = nil # release cancellation callback memory
|
fut.cancelcb = nil # release cancellation callback memory
|
||||||
for item in fut.callbacks.mitems():
|
for item in fut.callbacks.mitems():
|
||||||
if not(isNil(item.function)):
|
if not(isNil(item.function)):
|
||||||
callSoon(item.function, item.udata)
|
callSoon(item)
|
||||||
item = default(AsyncCallback) # release memory as early as possible
|
item = default(AsyncCallback) # release memory as early as possible
|
||||||
fut.callbacks = default(seq[AsyncCallback]) # release seq as well
|
fut.callbacks = default(seq[AsyncCallback]) # release seq as well
|
||||||
|
|
||||||
|
@ -177,8 +177,7 @@ elif unixPlatform:
|
|||||||
MSG_NOSIGNAL, SIGPIPE
|
MSG_NOSIGNAL, SIGPIPE
|
||||||
|
|
||||||
type
|
type
|
||||||
CallbackFunc* = proc (arg: pointer = nil) {.gcsafe.}
|
CallbackFunc* = proc (arg: pointer) {.gcsafe.}
|
||||||
CallSoonProc* = proc (c: CallbackFunc, u: pointer = nil) {.gcsafe.}
|
|
||||||
|
|
||||||
AsyncCallback* = object
|
AsyncCallback* = object
|
||||||
function*: CallbackFunc
|
function*: CallbackFunc
|
||||||
@ -206,9 +205,6 @@ type
|
|||||||
proc `<`(a, b: TimerCallback): bool =
|
proc `<`(a, b: TimerCallback): bool =
|
||||||
result = a.finishAt < b.finishAt
|
result = a.finishAt < b.finishAt
|
||||||
|
|
||||||
proc callSoon*(cbproc: CallbackFunc, data: pointer = nil) {.
|
|
||||||
gcsafe, raises: [Defect].}
|
|
||||||
|
|
||||||
func getAsyncTimestamp*(a: Duration): auto {.inline.} =
|
func getAsyncTimestamp*(a: Duration): auto {.inline.} =
|
||||||
## Return rounded up value of duration with milliseconds resolution.
|
## Return rounded up value of duration with milliseconds resolution.
|
||||||
##
|
##
|
||||||
@ -808,6 +804,22 @@ proc removeTimer*(at: uint64, cb: CallbackFunc, udata: pointer = nil) {.
|
|||||||
inline, deprecated: "Use removeTimer(Duration, cb, udata)".} =
|
inline, deprecated: "Use removeTimer(Duration, cb, udata)".} =
|
||||||
removeTimer(Moment.init(int64(at), Millisecond), cb, udata)
|
removeTimer(Moment.init(int64(at), Millisecond), cb, udata)
|
||||||
|
|
||||||
|
proc callSoon*(acb: AsyncCallback) {.gcsafe, raises: [Defect].} =
|
||||||
|
## Schedule `cbproc` to be called as soon as possible.
|
||||||
|
## The callback is called when control returns to the event loop.
|
||||||
|
getThreadDispatcher().callbacks.addLast(acb)
|
||||||
|
|
||||||
|
proc callSoon*(cbproc: CallbackFunc, data: pointer) {.
|
||||||
|
gcsafe, raises: [Defect].} =
|
||||||
|
## Schedule `cbproc` to be called as soon as possible.
|
||||||
|
## The callback is called when control returns to the event loop.
|
||||||
|
doAssert(not isNil(cbproc))
|
||||||
|
callSoon(AsyncCallback(function: cbproc, udata: data))
|
||||||
|
|
||||||
|
proc callSoon*(cbproc: CallbackFunc) {.
|
||||||
|
gcsafe, raises: [Defect].} =
|
||||||
|
callSoon(cbproc, nil)
|
||||||
|
|
||||||
include asyncfutures2
|
include asyncfutures2
|
||||||
|
|
||||||
proc sleepAsync*(duration: Duration): Future[void] =
|
proc sleepAsync*(duration: Duration): Future[void] =
|
||||||
@ -996,13 +1008,6 @@ proc wait*[T](fut: Future[T], timeout = -1): Future[T] {.
|
|||||||
|
|
||||||
include asyncmacro2
|
include asyncmacro2
|
||||||
|
|
||||||
proc callSoon*(cbproc: CallbackFunc, data: pointer = nil) =
|
|
||||||
## Schedule `cbproc` to be called as soon as possible.
|
|
||||||
## The callback is called when control returns to the event loop.
|
|
||||||
doAssert(not isNil(cbproc))
|
|
||||||
let acb = AsyncCallback(function: cbproc, udata: data)
|
|
||||||
getThreadDispatcher().callbacks.addLast(acb)
|
|
||||||
|
|
||||||
proc runForever*() =
|
proc runForever*() =
|
||||||
## Begins a never ending global dispatcher poll loop.
|
## Begins a never ending global dispatcher poll loop.
|
||||||
while true:
|
while true:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user