From 9a420c6b05840294ae2b42cea292f7f3e33397fc Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Mon, 11 Jan 2021 22:15:21 +0100 Subject: [PATCH] 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 --- chronos/asyncfutures2.nim | 2 +- chronos/asyncloop.nim | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/chronos/asyncfutures2.nim b/chronos/asyncfutures2.nim index 56613a6..4d87bf2 100644 --- a/chronos/asyncfutures2.nim +++ b/chronos/asyncfutures2.nim @@ -218,7 +218,7 @@ proc finish(fut: FutureBase, state: FutureState) = fut.cancelcb = nil # release cancellation callback memory for item in fut.callbacks.mitems(): if not(isNil(item.function)): - callSoon(item.function, item.udata) + callSoon(item) item = default(AsyncCallback) # release memory as early as possible fut.callbacks = default(seq[AsyncCallback]) # release seq as well diff --git a/chronos/asyncloop.nim b/chronos/asyncloop.nim index 428a396..ee8b9d9 100644 --- a/chronos/asyncloop.nim +++ b/chronos/asyncloop.nim @@ -177,8 +177,7 @@ elif unixPlatform: MSG_NOSIGNAL, SIGPIPE type - CallbackFunc* = proc (arg: pointer = nil) {.gcsafe.} - CallSoonProc* = proc (c: CallbackFunc, u: pointer = nil) {.gcsafe.} + CallbackFunc* = proc (arg: pointer) {.gcsafe.} AsyncCallback* = object function*: CallbackFunc @@ -206,9 +205,6 @@ type proc `<`(a, b: TimerCallback): bool = result = a.finishAt < b.finishAt -proc callSoon*(cbproc: CallbackFunc, data: pointer = nil) {. - gcsafe, raises: [Defect].} - func getAsyncTimestamp*(a: Duration): auto {.inline.} = ## 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)".} = 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 proc sleepAsync*(duration: Duration): Future[void] = @@ -996,13 +1008,6 @@ proc wait*[T](fut: Future[T], timeout = -1): Future[T] {. 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*() = ## Begins a never ending global dispatcher poll loop. while true: