From 1ca44151066f4e5b72e0b63b1e149b534720a2e8 Mon Sep 17 00:00:00 2001 From: cheatfate Date: Tue, 22 May 2018 13:43:42 +0300 Subject: [PATCH] Fix callSoon must be initialized for all platforms. --- asyncdispatch2/asyncloop.nim | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/asyncdispatch2/asyncloop.nim b/asyncdispatch2/asyncloop.nim index 06cff7f..16c13e9 100644 --- a/asyncdispatch2/asyncloop.nim +++ b/asyncdispatch2/asyncloop.nim @@ -179,7 +179,7 @@ proc `<`(a, b: TimerCallback): bool = proc callSoon(cbproc: CallbackFunc, data: pointer = nil) {.gcsafe.} -proc initCallSoonProc = +proc initCallSoonProc() = if asyncfutures2.getCallSoonProc().isNil: asyncfutures2.setCallSoonProc(callSoon) @@ -382,7 +382,6 @@ when defined(windows) or defined(nimdoc): proc contains*(disp: PDispatcher, fd: AsyncFD): bool = return fd in disp.handles - initAPI() else: import selectors from posix import EINTR, EAGAIN, EINPROGRESS, EWOULDBLOCK, MSG_PEEK, @@ -560,6 +559,9 @@ else: var callable = loop.callbacks.popFirst() callable.function(callable.udata) + proc initAPI() = + discard getGlobalDispatcher() + proc addTimer*(at: uint64, cb: CallbackFunc, udata: pointer = nil) = let loop = getGlobalDispatcher() var tcb = TimerCallback(finishAt: at, @@ -629,3 +631,6 @@ proc waitFor*[T](fut: Future[T]): T = poll() fut.read + +# Global API and callSoon initialization. +initAPI()