Added deques module, deprecating queues

This commit is contained in:
Ruslan Mustakov 2016-11-22 21:53:41 +07:00
commit 2c146445bc
10 changed files with 297 additions and 25 deletions

View file

@ -11,7 +11,7 @@ include "system/inclrtl"
import os, oids, tables, strutils, times, heapqueue, lists
import nativesockets, net, queues
import nativesockets, net, deques
export Port, SocketFlag
@ -135,7 +135,7 @@ include "../includes/asyncfutures"
type
PDispatcherBase = ref object of RootRef
timers: HeapQueue[tuple[finishAt: float, fut: Future[void]]]
callbacks: Queue[proc ()]
callbacks: Deque[proc ()]
proc processTimers(p: PDispatcherBase) {.inline.} =
while p.timers.len > 0 and epochTime() >= p.timers[0].finishAt:
@ -143,7 +143,7 @@ proc processTimers(p: PDispatcherBase) {.inline.} =
proc processPendingCallbacks(p: PDispatcherBase) =
while p.callbacks.len > 0:
var cb = p.callbacks.dequeue()
var cb = p.callbacks.popFirst()
cb()
proc adjustedTimeout(p: PDispatcherBase, timeout: int): int {.inline.} =
@ -1114,7 +1114,7 @@ else:
new result
result.selector = newSelector[AsyncData]()
result.timers.newHeapQueue()
result.callbacks = initQueue[proc ()](64)
result.callbacks = initDeque[proc ()](64)
var gDisp{.threadvar.}: PDispatcher ## Global dispatcher
proc getGlobalDispatcher*(): PDispatcher =
@ -1638,7 +1638,7 @@ proc recvLine*(socket: AsyncFD): Future[string] {.async.} =
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.enqueue(cbproc)
getGlobalDispatcher().callbacks.addLast(cbproc)
proc runForever*() =
## Begins a never ending global dispatcher poll loop.