This commit is contained in:
Andreas Rumpf 2019-03-06 10:15:27 +01:00
commit 32c9ca605e
2 changed files with 23 additions and 10 deletions

View file

@ -167,7 +167,7 @@ export asyncstreams
type type
PDispatcherBase = ref object of RootRef PDispatcherBase = ref object of RootRef
timers*: HeapQueue[tuple[finishAt: float, fut: Future[void]]] timers*: HeapQueue[tuple[finishAt: float, fut: Future[void]]]
callbacks*: Deque[proc ()] callbacks*: Deque[proc () {.gcsafe.}]
proc processTimers( proc processTimers(
p: PDispatcherBase, didSomeWork: var bool p: PDispatcherBase, didSomeWork: var bool
@ -200,7 +200,9 @@ 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.}) {.gcsafe.}
## Schedule `cbproc` to be called as soon as possible.
## The callback is called when control returns to the event loop.
proc initCallSoonProc = proc initCallSoonProc =
if asyncfutures.getCallSoonProc().isNil: if asyncfutures.getCallSoonProc().isNil:
@ -1806,9 +1808,7 @@ proc readAll*(future: FutureStream[string]): Future[string] {.async.} =
else: else:
break break
proc callSoon*(cbproc: proc ()) = proc callSoon(cbproc: proc () {.gcsafe.}) =
## Schedule `cbproc` to be called as soon as possible.
## The callback is called when control returns to the event loop.
getGlobalDispatcher().callbacks.addLast(cbproc) getGlobalDispatcher().callbacks.addLast(cbproc)
proc runForever*() = proc runForever*() =

View file

@ -1,16 +1,29 @@
discard """ discard """
output: "0" output: '''0
hello'''
""" """
type type
CircAlloc* [Size: static[int] , T] = tuple CircAlloc*[Size: static[int], T] = tuple
baseArray : array[Size,T] baseArray: array[Size,T]
index : uint16 index: uint16
type type
Job = object of RootObj Job = object of RootObj
var foo {.threadvar.}: CircAlloc[1,Job] var foo {.threadvar.}: CircAlloc[1, Job]
when true: when true:
echo foo.index echo foo.index
# bug #10795
import asyncdispatch
import threadpool
proc f1() =
waitFor sleepAsync(100)
echo "hello"
spawn f1()
sync()