From c2b16b46ecf9e62e411e5b7e6d4d861c43b1b0fe Mon Sep 17 00:00:00 2001 From: narimiran Date: Mon, 12 Nov 2018 15:40:33 +0100 Subject: [PATCH] export `asyncdispatch.callSoon` (fixes #7192) --- lib/pure/asyncdispatch.nim | 7 ++++--- tests/async/t7192.nim | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 tests/async/t7192.nim diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index 5ef791cfe95a4..443c65f266a3f 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -16,7 +16,8 @@ import asyncfutures except callSoon import nativesockets, net, deques export Port, SocketFlag -export asyncfutures, asyncstreams +export asyncfutures except callSoon +export asyncstreams #{.injectStmt: newGcInvariant().} @@ -199,7 +200,7 @@ proc adjustTimeout(pollTimeout: int, nextTimer: Option[int]): int {.inline.} = if pollTimeout == -1: return result = min(pollTimeout, result) -proc callSoon(cbproc: proc ()) {.gcsafe.} +proc callSoon*(cbproc: proc ()) {.gcsafe.} proc initCallSoonProc = if asyncfutures.getCallSoonProc().isNil: @@ -1640,7 +1641,7 @@ proc recvLine*(socket: AsyncFD): Future[string] {.async, deprecated.} = return add(result, c) -proc callSoon(cbproc: proc ()) = +proc callSoon*(cbproc: proc ()) = ## Schedule `cbproc` to be called as soon as possible. ## The callback is called when control returns to the event loop. getGlobalDispatcher().callbacks.addLast(cbproc) diff --git a/tests/async/t7192.nim b/tests/async/t7192.nim new file mode 100644 index 0000000000000..c380f93e14251 --- /dev/null +++ b/tests/async/t7192.nim @@ -0,0 +1,14 @@ +discard """ +output: ''' +testCallback() +''' +""" + +import asyncdispatch + +proc testCallback() = + echo "testCallback()" + +when isMainModule: + callSoon(testCallback) + poll()