Merge pull request #9687 from narimiran/fix-7192
export `asyncdispatch.callSoon` (fixes #7192)
This commit is contained in:
commit
679a52f53c
2 changed files with 18 additions and 3 deletions
|
|
@ -16,7 +16,8 @@ import asyncfutures except callSoon
|
||||||
import nativesockets, net, deques
|
import nativesockets, net, deques
|
||||||
|
|
||||||
export Port, SocketFlag
|
export Port, SocketFlag
|
||||||
export asyncfutures, asyncstreams
|
export asyncfutures except callSoon
|
||||||
|
export asyncstreams
|
||||||
|
|
||||||
#{.injectStmt: newGcInvariant().}
|
#{.injectStmt: newGcInvariant().}
|
||||||
|
|
||||||
|
|
@ -199,7 +200,7 @@ proc adjustTimeout(pollTimeout: int, nextTimer: Option[int]): int {.inline.} =
|
||||||
if pollTimeout == -1: return
|
if pollTimeout == -1: return
|
||||||
result = min(pollTimeout, result)
|
result = min(pollTimeout, result)
|
||||||
|
|
||||||
proc callSoon(cbproc: proc ()) {.gcsafe.}
|
proc callSoon*(cbproc: proc ()) {.gcsafe.}
|
||||||
|
|
||||||
proc initCallSoonProc =
|
proc initCallSoonProc =
|
||||||
if asyncfutures.getCallSoonProc().isNil:
|
if asyncfutures.getCallSoonProc().isNil:
|
||||||
|
|
@ -1640,7 +1641,7 @@ proc recvLine*(socket: AsyncFD): Future[string] {.async, deprecated.} =
|
||||||
return
|
return
|
||||||
add(result, c)
|
add(result, c)
|
||||||
|
|
||||||
proc callSoon(cbproc: proc ()) =
|
proc callSoon*(cbproc: proc ()) =
|
||||||
## Schedule `cbproc` to be called as soon as possible.
|
## Schedule `cbproc` to be called as soon as possible.
|
||||||
## The callback is called when control returns to the event loop.
|
## The callback is called when control returns to the event loop.
|
||||||
getGlobalDispatcher().callbacks.addLast(cbproc)
|
getGlobalDispatcher().callbacks.addLast(cbproc)
|
||||||
|
|
|
||||||
14
tests/async/t7192.nim
Normal file
14
tests/async/t7192.nim
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
discard """
|
||||||
|
output: '''
|
||||||
|
testCallback()
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
import asyncdispatch
|
||||||
|
|
||||||
|
proc testCallback() =
|
||||||
|
echo "testCallback()"
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
callSoon(testCallback)
|
||||||
|
poll()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue