API reference: chronos

asyncfutures2

Types

CallbackFunc

undefined

CallbackFunc = proc (arg: pointer = nil) {.gcsafe.}
1

CallSoonProc

undefined

CallSoonProc = proc (c: CallbackFunc; u: pointer = nil) {.gcsafe.}
1

AsyncCallback

undefined

AsyncCallback = object
  function*: CallbackFunc
  udata*: pointer
  deleted*: bool
1
2
3
4

FutureState

undefined

FutureState {.pure.} = enum
  Pending, Finished, Cancelled, Failed
1
2

FutureBase

Untyped future.

FutureBase = ref object of RootObj
  location: array[2, ptr SrcLoc]
  callbacks: Deque[AsyncCallback]
  cancelcb*: CallbackFunc
  child*: FutureBase
  state*: FutureState
  error*: ref Exception         ## Stored exception
  errorStackTrace*: StackTrace
  stackTrace: StackTrace       ## For debugging purposes only.
  id: int
1
2
3
4
5
6
7
8
9
10

Future

Typed future.

Future[T] = ref object of FutureBase
  value: T                     ## Stored value
1
2

FutureStr

Future to hold GC strings

FutureStr[T] = ref object of Future[T]
  gcholder*: string
1
2

FutureSeq

Future to hold GC seqs

FutureSeq[A; B] = ref object of Future[A]
  gcholder*: seq[B]
1
2

FutureVar

undefined

FutureVar[T] = distinct Future[T]
1

FutureError

undefined

FutureError = object of Exception
  cause*: FutureBase
1
2

CancelledError

undefined

CancelledError = object of FutureError
1

Procs


getCallSoonProc

Get current implementation of callSoon.

proc getCallSoonProc(): CallSoonProc {.gcsafe, raises: [], tags: [].}
1

setCallSoonProc

Change current implementation of callSoon.

proc setCallSoonProc(p: CallSoonProc) {.raises: [], tags: [].}
1

callSoon

Call cbproc "soon".

proc callSoon(c: CallbackFunc; u: pointer = nil) {.raises: [Exception],
    tags: [RootEffect].}
1
2

clean

Resets the finished status of future.

proc clean[T](future: FutureVar[T])
1

finished

Determines whether future has completed.

True may indicate an error or a value. Use failed to distinguish.

proc finished(future: FutureBase | FutureVar): bool {.inline.}
1

cancelled

Determines whether future has cancelled.

proc cancelled(future: FutureBase): bool {.inline, raises: [], tags: [].}
1

failed

Determines whether future completed with an error.

proc failed(future: FutureBase): bool {.inline, raises: [], tags: [].}
1

addCallback

Adds the callbacks proc to be called when the future completes.

If future has already completed then cb will be called immediately.

proc addCallback(future: FutureBase; cb: CallbackFunc; udata: pointer = nil) {.
    raises: [Exception], tags: [RootEffect].}
1
2

addCallback

Adds the callbacks proc to be called when the future completes.

If future has already completed then cb will be called immediately.

proc addCallback[T](future: Future[T]; cb: CallbackFunc)
1

removeCallback

undefined

proc removeCallback(future: FutureBase; cb: CallbackFunc; udata: pointer = nil) {.
    raises: [Exception], tags: [RootEffect].}
1
2

removeCallback

undefined

proc removeCallback[T](future: Future[T]; cb: CallbackFunc)
1

callback=

Clears the list of callbacks and sets the callback proc to be called when the future completes.

If future has already completed then cb will be called immediately.

It's recommended to use addCallback or then instead.

proc callback=(future: FutureBase; cb: CallbackFunc; udata: pointer = nil) {.
    raises: [IndexError, Exception], tags: [RootEffect].}
1
2

callback=

Sets the callback proc to be called when the future completes.

If future has already completed then cb will be called immediately.

proc callback=[T](future: Future[T]; cb: CallbackFunc)
1

cancelCallback=

Sets the callback procedure to be called when the future is cancelled.

This callback will be called immediately as future.cancel() invoked.

proc cancelCallback=[T](future: Future[T]; cb: CallbackFunc)
1

`####

undefined

proc `#### `####  

 undefined 

```nim(entries: seq[StackTraceEntry]): string {.raises: [ValueError], tags: [].}
1
2
3
4
5

internalCheckComplete

undefined

proc internalCheckComplete(fut: FutureBase) {.raises: [ValueError, Exception],
    tags: [].}
1
2

internalRead

undefined

proc internalRead[T](fut: Future[T] | FutureVar[T]): T {.inline.}
1

read

Retrieves the value of future. Future must be finished otherwise this function will fail with a ValueError exception.

If the result of the future is an error then that error will be raised.

proc read[T](future: Future[T] | FutureVar[T]): T
1

readError

Retrieves the exception stored in future.

An ValueError exception will be thrown if no exception exists in the specified Future.

proc readError[T](future: Future[T]): ref Exception
1

mget

Returns a mutable value stored in future.

Unlike read, this function will not raise an exception if the Future has not been finished.

proc mget[T](future: FutureVar[T]): var T
1

asyncCheck

Sets a callback on future which raises an exception if the future finished with an error.

This should be used instead of discard to discard void futures.

proc asyncCheck[T](future: Future[T])
1

asyncDiscard

This is async workaround for discard Future[T].

proc asyncDiscard[T](future: Future[T])
1

and

Returns a future which will complete once both fut1 and fut2 complete.

If cancelled, fut1 and fut2 futures WILL NOT BE cancelled.

proc `and`[T, Y](fut1: Future[T]; fut2: Future[Y]): Future[void] {.
    deprecated: "Use allFutures[T](varargs[Future[T]])".}
1
2

or

Returns a future which will complete once either fut1 or fut2 complete.

If cancelled, fut1 and fut2 futures WILL NOT BE cancelled.

proc `or`[T, Y](fut1: Future[T]; fut2: Future[Y]): Future[void] {.
    deprecated: "Use one[T](varargs[Future[T]])".}
1
2

all

Returns a future which will complete once all futures in futs complete. If the argument is empty, the returned future completes immediately.

If the awaited futures are not Future[void], the returned future will hold the values of all awaited futures in a sequence.

If the awaited futures are Future[void], this proc returns Future[void].

Note, that if one of the futures in futs will fail, result of all() will also be failed with error from failed future.

TODO: This procedure has bug on handling cancelled futures from futs. So if future from futs list become cancelled, what must be returned? You can't cancel result retFuture because in such way infinite recursion will happen.

proc all[T](futs: varargs[Future[T]]): auto {.
    deprecated: "Use allFutures(varargs[Future[T]])".}
1
2

oneIndex

Returns a future which will complete once one of the futures in futs complete.

If the argument is empty, the returned future FAILS immediately.

Returned future will hold index of completed/failed future in futs argument.

proc oneIndex[T](futs: varargs[Future[T]]): Future[int] {.
    deprecated: "Use one[T](varargs[Future[T]])".}
1
2

oneValue

Returns a future which will complete once one of the futures in futs complete.

If the argument is empty, returned future FAILS immediately.

Returned future will hold value of completed futs future, or error if future was failed.

proc oneValue[T](futs: varargs[Future[T]]): Future[T] {.
    deprecated: "Use one[T](varargs[Future[T]])".}
1
2

cancelAndWait

Cancel future future and wait until it completes.

proc cancelAndWait[T](future: Future[T]): Future[void]
1

allFutures

Returns a future which will complete only when all futures in futs will be completed, failed or canceled.

If the argument is empty, the returned future COMPLETES immediately.

On cancel all the awaited futures futs WILL NOT BE cancelled.

proc allFutures[T](futs: varargs[Future[T]]): Future[void]
1

one

Returns a future which will complete and return completed Future[T] inside, when one of the futures in futs will be completed, failed or canceled.

If the argument is empty, the returned future FAILS immediately.

On success returned Future will hold index in futs array.

On cancel futures in futs WILL NOT BE cancelled.

proc one[T](futs: varargs[Future[T]]): Future[Future[T]]
1

Templates


newFuture

Creates a new future.

Specifying fromProc, which is a string specifying the name of the proc that this future belongs to, is a good habit as it helps with debugging.

template newFuture[T; ](fromProc: static[string] = ""): auto
1

newFutureSeq

Create a new future which can hold/preserve GC sequence until future will not be completed.

Specifying fromProc, which is a string specifying the name of the proc that this future belongs to, is a good habit as it helps with debugging.

template newFutureSeq[A; B; ](fromProc: static[string] = ""): auto
1

newFutureStr

Create a new future which can hold/preserve GC string until future will not be completed.

Specifying fromProc, which is a string specifying the name of the proc that this future belongs to, is a good habit as it helps with debugging.

template newFutureStr[T; ](fromProc: static[string] = ""): auto
1

newFutureVar

Create a new FutureVar. This Future type is ideally suited for situations where you want to avoid unnecessary allocations of Futures.

Specifying fromProc, which is a string specifying the name of the proc that this future belongs to, is a good habit as it helps with debugging.

template newFutureVar[T; ](fromProc: static[string] = ""): auto
1

complete

Completes future with value val.

template complete[T](future: Future[T]; val: T)
1

complete

Completes a void future.

template complete(future: Future[void])
1

complete

Completes a FutureVar.

template complete[T](futvar: FutureVar[T])
1

complete

Completes a FutureVar with value val.

Any previously stored value will be overwritten.

template complete[T](futvar: FutureVar[T]; val: T)
1

fail

Completes future with error.

template fail[T](future: Future[T]; error: ref Exception)
1

cancel

Cancel future.

template cancel[T](future: Future[T])
1

asyncloop

Types

AsyncError

Generic async exception

AsyncError = object of CatchableError
1

AsyncTimeoutError

Timeout exception

AsyncTimeoutError = object of AsyncError
1

TimerCallback

undefined

TimerCallback = object
  finishAt*: Moment
  function*: AsyncCallback
1
2
3

TrackerBase

undefined

TrackerBase = ref object of RootRef
  id*: string
  dump*: proc (): string {.gcsafe.}
  isLeaked*: proc (): bool {.gcsafe.}
1
2
3
4

CompletionData

undefined

CompletionData = object
  fd*: AsyncFD
  cb*: CallbackFunc
  errCode*: OSErrorCode
  bytesCount*: int32
  udata*: pointer
1
2
3
4
5
6

CustomOverlapped

undefined

CustomOverlapped = object of OVERLAPPED
  data*: CompletionData
1
2

PDispatcher

undefined

PDispatcher = ref object of PDispatcherBase
  ioPort: Handle
  handles: HashSet[AsyncFD]
  connectEx*: WSAPROC_CONNECTEX
  acceptEx*: WSAPROC_ACCEPTEX
  getAcceptExSockAddrs*: WSAPROC_GETACCEPTEXSOCKADDRS
  transmitFile*: WSAPROC_TRANSMITFILE
1
2
3
4
5
6
7

PtrCustomOverlapped

undefined

PtrCustomOverlapped = ptr CustomOverlapped
1

RefCustomOverlapped

undefined

RefCustomOverlapped = ref CustomOverlapped
1

AsyncFD

undefined

AsyncFD = distinct int
1

Procs


==

undefined

proc `==`(x: AsyncFD; y: AsyncFD): bool {.borrow.}
1

newDispatcher

Creates a new Dispatcher instance.

proc newDispatcher(): PDispatcher {.raises: [], tags: [].}
1

setGlobalDispatcher

Set current thread's dispatcher instance to disp.

proc setGlobalDispatcher(disp: PDispatcher) {.raises: [Exception], tags: [RootEffect].}
1

getGlobalDispatcher

Returns current thread's dispatcher instance.

proc getGlobalDispatcher(): PDispatcher {.raises: [Exception], tags: [RootEffect].}
1

getIoHandler

Returns the underlying IO Completion Port handle (Windows) or selector (Unix) for the specified dispatcher.

proc getIoHandler(disp: PDispatcher): Handle {.raises: [], tags: [].}
1

register

Register file descriptor fd in thread's dispatcher.

proc register(fd: AsyncFD) {.raises: [Exception, OSError], tags: [RootEffect].}
1

poll

Perform single asynchronous step.

proc poll() {.raises: [Exception, OSError, IndexError], tags: [RootEffect].}
1

closeSocket

Closes a socket and ensures that it is unregistered.

proc closeSocket(fd: AsyncFD; aftercb: CallbackFunc = nil) {.raises: [Exception],
    tags: [RootEffect].}
1
2

closeHandle

Closes a (pipe/file) handle and ensures that it is unregistered.

proc closeHandle(fd: AsyncFD; aftercb: CallbackFunc = nil) {.raises: [Exception],
    tags: [RootEffect].}
1
2

unregister

Unregisters fd.

proc unregister(fd: AsyncFD) {.raises: [Exception], tags: [RootEffect].}
1

contains

Returns true if fd is registered in thread's dispatcher.

proc contains(disp: PDispatcher; fd: AsyncFD): bool {.raises: [], tags: [].}
1

addTimer

Arrange for the callback cb to be called at the given absolute timestamp at. You can also pass udata to callback.

proc addTimer(at: Moment; cb: CallbackFunc; udata: pointer = nil) {.raises: [Exception],
    tags: [RootEffect].}
1
2

addTimer

undefined

proc addTimer(at: int64; cb: CallbackFunc; udata: pointer = nil) {.inline,
    deprecated: "Use addTimer(Duration, cb, udata)", raises: [Exception],
    tags: [RootEffect].}
1
2
3

addTimer

undefined

proc addTimer(at: uint64; cb: CallbackFunc; udata: pointer = nil) {.inline,
    deprecated: "Use addTimer(Duration, cb, udata)", raises: [Exception],
    tags: [RootEffect].}
1
2
3

removeTimer

Remove timer callback cb with absolute timestamp at from waiting queue.

proc removeTimer(at: Moment; cb: CallbackFunc; udata: pointer = nil) {.
    raises: [Exception], tags: [RootEffect].}
1
2

removeTimer

undefined

proc removeTimer(at: int64; cb: CallbackFunc; udata: pointer = nil) {.inline,
    deprecated: "Use removeTimer(Duration, cb, udata)", raises: [Exception],
    tags: [RootEffect].}
1
2
3

removeTimer

undefined

proc removeTimer(at: uint64; cb: CallbackFunc; udata: pointer = nil) {.inline,
    deprecated: "Use removeTimer(Duration, cb, udata)", raises: [Exception],
    tags: [RootEffect].}
1
2
3

sleepAsync

Suspends the execution of the current async procedure for the next duration time.

proc sleepAsync(duration: Duration): Future[void] {.
    raises: [Exception, FutureError, IndexError], tags: [RootEffect].}
1
2

sleepAsync

undefined

proc sleepAsync(ms: int): Future[void] {.inline,
                                     deprecated: "Use sleepAsync(Duration)", raises: [
    Exception, FutureError, IndexError], tags: [RootEffect].}
1
2
3

withTimeout

Returns a future which will complete once fut completes or after timeout milliseconds has elapsed.

If fut completes first the returned future will hold true, otherwise, if timeout milliseconds has elapsed first, the returned future will hold false.

proc withTimeout[T](fut: Future[T]; timeout: Duration): Future[bool]
1

withTimeout

undefined

proc withTimeout[T](fut: Future[T]; timeout: int): Future[bool] {.inline,
    deprecated: "Use withTimeout(Future[T], Duration)".}
1
2

wait

Returns a future which will complete once future fut completes or if timeout of timeout milliseconds has been expired.

If timeout is -1, then statement await wait(fut) is equal to await fut.

TODO: In case when fut got cancelled, what result Future[T] should return, because it can't be cancelled too.

proc wait[T](fut: Future[T]; timeout = InfiniteDuration): Future[T]
1

wait

undefined

proc wait[T](fut: Future[T]; timeout = -1): Future[T] {.inline,
    deprecated: "Use wait(Future[T], Duration)".}
1
2

runForever

Begins a never ending global dispatcher poll loop.

proc runForever() {.raises: [Exception, OSError, IndexError], tags: [RootEffect].}
1

waitFor

Blocks the current thread until the specified future completes.

proc waitFor[T](fut: Future[T]): T
1

addTracker

Add new tracker object to current thread dispatcher with identifier id.

proc addTracker[T](id: string; tracker: T)
1

getTracker

Get tracker from current thread dispatcher using identifier id.

proc getTracker(id: string): TrackerBase {.raises: [Exception], tags: [RootEffect].}
1

Templates


await

undefined

template await[T](f: Future[T]): auto
1

awaitne

undefined

template awaitne[T](f: Future[T]): Future[T]
1

asyncsync

Types

AsyncLock

A primitive lock is a synchronization primitive that is not owned by a particular coroutine when locked. A primitive lock is in one of two states, locked or unlocked.

When more than one coroutine is blocked in acquire() waiting for the state to turn to unlocked, only one coroutine proceeds when a release() call resets the state to unlocked; first coroutine which is blocked in acquire() is being processed.

AsyncLock = ref object of RootRef
  locked: bool
  waiters: seq[Future[void]]
1
2
3

AsyncEvent

A primitive event object.

An event manages a flag that can be set to true with the fire() procedure and reset to false with the clear() procedure. The wait() coroutine blocks until the flag is false.

If more than one coroutine blocked in wait() waiting for event state to be signaled, when event get fired, then all coroutines continue proceeds in order, they have entered waiting state.

AsyncEvent = ref object of RootRef
  flag: bool
  waiters: seq[Future[void]]
1
2
3

AsyncQueue

A queue, useful for coordinating producer and consumer coroutines.

If maxsize is less than or equal to zero, the queue size is infinite. If it is an integer greater than 0, then "await put()" will block when the queue reaches maxsize, until an item is removed by "await get()".

AsyncQueue[T] = ref object of RootRef
  getters: seq[Future[void]]
  putters: seq[Future[void]]
  queue: Deque[T]
  maxsize: int
1
2
3
4
5

AsyncQueueEmptyError

AsyncQueue is empty.

AsyncQueueEmptyError = object of Exception
1

AsyncQueueFullError

AsyncQueue is full.

AsyncQueueFullError = object of Exception
1

AsyncLockError

AsyncLock is either locked or unlocked.

AsyncLockError = object of Exception
1

Procs


newAsyncLock

Creates new asynchronous lock AsyncLock.

Lock is created in the unlocked state. When the state is unlocked, acquire() changes the state to locked and returns immediately. When the state is locked, acquire() blocks until a call to release() in another coroutine changes it to unlocked.

The release() procedure changes the state to unlocked and returns immediately.

proc newAsyncLock(): AsyncLock {.raises: [Exception], tags: [RootEffect].}
1

acquire

undefined

proc acquire(lock: AsyncLock): Future[void] {.stackTrace: false,
    raises: [FutureError, IndexError], tags: [RootEffect].}
1
2

locked

Return true if the lock lock is acquired, false otherwise.

proc locked(lock: AsyncLock): bool {.raises: [], tags: [].}
1

release

Release a lock lock.

When the lock is locked, reset it to unlocked, and return. If any other coroutines are blocked waiting for the lock to become unlocked, allow exactly one of them to proceed.

proc release(lock: AsyncLock) {.raises: [FutureError, IndexError, Exception,
                                     AsyncLockError], tags: [RootEffect].}
1
2

newAsyncEvent

Creates new asyncronous event AsyncEvent.

An event manages a flag that can be set to true with the fire() procedure and reset to false with the clear() procedure. The wait() procedure blocks until the flag is true. The flag is initially false.

proc newAsyncEvent(): AsyncEvent {.raises: [Exception], tags: [RootEffect].}
1

wait

undefined

proc wait(event: AsyncEvent): Future[void] {.stackTrace: false,
    raises: [FutureError, IndexError], tags: [RootEffect].}
1
2

fire

Set the internal flag of event to true. All tasks waiting for it to become true are awakened. Task that call wait() once the flag is true will not block at all.

proc fire(event: AsyncEvent) {.raises: [FutureError, IndexError, Exception],
                            tags: [RootEffect].}
1
2

clear

Reset the internal flag of event to false. Subsequently, tasks calling wait() will block until fire() is called to set the internal flag to true again.

proc clear(event: AsyncEvent) {.raises: [], tags: [].}
1

isSet

Return true if and only if the internal flag of event is true.

proc isSet(event: AsyncEvent): bool {.raises: [], tags: [].}
1

newAsyncQueue

Creates a new asynchronous queue AsyncQueue.

proc newAsyncQueue[T](maxsize: int = 0): AsyncQueue[T]
1

full

Return true if there are maxsize items in the queue.

Note: If the aq was initialized with maxsize = 0 (default), then full() is never true.

proc full[T](aq: AsyncQueue[T]): bool {.inline.}
1

empty

Return true if the queue is empty, false otherwise.

proc empty[T](aq: AsyncQueue[T]): bool {.inline.}
1

addFirstNoWait

Put an item item to the beginning of the queue aq immediately.

If queue aq is full, then AsyncQueueFullError exception raised.

proc addFirstNoWait[T](aq: AsyncQueue[T]; item: T)
1

addLastNoWait

Put an item item at the end of the queue aq immediately.

If queue aq is full, then AsyncQueueFullError exception raised.

proc addLastNoWait[T](aq: AsyncQueue[T]; item: T)
1

popFirstNoWait

Get an item from the beginning of the queue aq immediately.

If queue aq is empty, then AsyncQueueEmptyError exception raised.

proc popFirstNoWait[T](aq: AsyncQueue[T]): T
1

popLastNoWait

Get an item from the end of the queue aq immediately.

If queue aq is empty, then AsyncQueueEmptyError exception raised.

proc popLastNoWait[T](aq: AsyncQueue[T]): T
1

addFirst

undefined

proc addFirst[T](aq: AsyncQueue[T]; item: T): Future[void] {.stackTrace: false.}
1

addLast

undefined

proc addLast[T](aq: AsyncQueue[T]; item: T): Future[void] {.stackTrace: false.}
1

popFirst

undefined

proc popFirst[T](aq: AsyncQueue[T]): Future[T] {.stackTrace: false.}
1

popLast

undefined

proc popLast[T](aq: AsyncQueue[T]): Future[T] {.stackTrace: false.}
1

putNoWait

Alias of addLastNoWait().

proc putNoWait[T](aq: AsyncQueue[T]; item: T) {.inline.}
1

getNoWait

Alias of popFirstNoWait().

proc getNoWait[T](aq: AsyncQueue[T]): T {.inline.}
1

put

Alias of addLast().

proc put[T](aq: AsyncQueue[T]; item: T): Future[void] {.inline.}
1

get

Alias of popFirst().

proc get[T](aq: AsyncQueue[T]): Future[T] {.inline.}
1

clear

Clears all elements of queue aq.

proc clear[T](aq: AsyncQueue[T]) {.inline.}
1

len

Return the number of elements in aq.

proc len[T](aq: AsyncQueue[T]): int {.inline.}
1

size

Return the maximum number of elements in aq.

proc size[T](aq: AsyncQueue[T]): int {.inline.}
1

[]

Access the i-th element of aq by order from first to last. aq[0] is the first element, aq[^1] is the last element.

proc `[]`[T](aq: AsyncQueue[T]; i: Natural): T {.inline.}
1

[]

Access the i-th element of aq by order from first to last. aq[0] is the first element, aq[^1] is the last element.

proc `[]`[T](aq: AsyncQueue[T]; i: BackwardsIndex): T {.inline.}
1

[]=

Change the i-th element of aq.

proc `[]=`[T](aq: AsyncQueue[T]; i: Natural; item: T) {.inline.}
1

[]=

Change the i-th element of aq.

proc `[]=`[T](aq: AsyncQueue[T]; i: BackwardsIndex; item: T) {.inline.}
1

contains

Return true if item is in aq or false if not found. Usually used via the in operator.

proc contains[T](aq: AsyncQueue[T]; item: T): bool {.inline.}
1

`####

Turn an async queue aq into its string representation.

proc `#### `####  

 Turn an async queue <tt class="docutils literal"><span class="pre">aq</span></tt> into its string representation. 

```nim[T](aq: AsyncQueue[T]): string
1
2
3
4
5

Templates


handles

Types


Procs


setSocketBlocking

Sets blocking mode on socket.

proc setSocketBlocking(s: SocketHandle; blocking: bool): bool {.raises: [], tags: [].}
1

setSockOpt

setsockopt() for integer options. Returns true on success, false on error.

proc setSockOpt(socket: AsyncFD; level, optname, optval: int): bool {.raises: [], tags: [].}
1

setSockOpt

setsockopt() for custom options (pointer and length). Returns true on success, false on error.

proc setSockOpt(socket: AsyncFD; level, optname: int; value: pointer; valuelen: int): bool {.
    raises: [], tags: [].}
1
2

getSockOpt

getsockopt() for integer options. Returns true on success, false on error.

proc getSockOpt(socket: AsyncFD; level, optname: int; value: var int): bool {.raises: [],
    tags: [].}
1
2

getSockOpt

getsockopt() for custom options (pointer and length). Returns true on success, false on error.

proc getSockOpt(socket: AsyncFD; level, optname: int; value: pointer; valuelen: var int): bool {.
    raises: [], tags: [].}
1
2

getSocketError

Recover error code associated with socket handle socket.

proc getSocketError(socket: AsyncFD; err: var int): bool {.raises: [], tags: [].}
1

createAsyncSocket

Creates new asynchronous socket. Returns asyncInvalidSocket on error.

proc createAsyncSocket(domain: Domain; sockType: SockType; protocol: Protocol): AsyncFD {.
    raises: [Exception, OSError], tags: [RootEffect].}
1
2

wrapAsyncSocket

Wraps socket to asynchronous socket handle. Return asyncInvalidSocket on error.

proc wrapAsyncSocket(sock: SocketHandle): AsyncFD {.raises: [Exception, OSError],
    tags: [RootEffect].}
1
2

createAsyncPipe

Create new asynchronouse pipe. Returns tuple of read pipe handle and write pipe handleasyncInvalidPipe on error.

proc createAsyncPipe(): tuple[read: AsyncFD, write: AsyncFD] {.raises: [], tags: [].}
1

Templates


sendfile

Types


Procs


sendfile

Copies data between file descriptor infd and outfd. Because this copying is done within the kernel, sendfile() is more efficient than the combination of read(2) and write(2), which would require transferring data to and from user space.

infd should be a file descriptor opened for reading and outfd should be a descriptor opened for writing.

The infd argument must correspond to a file which supports mmap(2)-like operations (i.e., it cannot be a socket).

offset the file offset from which sendfile() will start reading data from infd.

count is the number of bytes to copy between the file descriptors. On exit count will hold number of bytes actually transferred between file descriptors.

If the transfer was successful, the number of bytes written to outfd is stored in count, and 0 returned. Note that a successful call to sendfile() may write fewer bytes than requested; the caller should be prepared to retry the call if there were unsent bytes.

On error, -1 is returned.

proc sendfile(outfd, infd: int; offset: int; count: var int): int {.raises: [], tags: [].}
1

Templates


srcloc

Types

SrcLoc

undefined

SrcLoc = object
  procedure*: cstring
  file*: cstring
  line*: int
1
2
3
4

Procs


`####

undefined

proc `#### `####  

 undefined 

```nim(loc: ptr SrcLoc): string {.raises: [], tags: [].}
1
2
3
4
5

Templates


getSrcLocation

undefined

template getSrcLocation(procedure: static string = ""): ptr SrcLoc
1

timer

Types

Moment

A Moment in time. Its value has no direct meaning, but can be compared with other Moments. Moments are captured using a monotonically non-decreasing clock (by default).

Moment = object
  value: int64
1
2

Duration

A Duration is the interval between to points in time.

Duration = object
  value: int64
1
2

SomeIntegerI64

undefined

SomeIntegerI64 = SomeSignedInt | uint8 | uint16 | uint32
1

Procs


QueryPerformanceCounter

undefined

proc QueryPerformanceCounter(res: var uint64) {.importc: "QueryPerformanceCounter",
    stdcall, dynlib: "kernel32".}
1
2

fastEpochTime

Procedure's resolution is millisecond.

proc fastEpochTime(): uint64 {.inline, deprecated: "Use Moment.now()", raises: [],
                            tags: [].}
1
2

now

Returns current moment in time as Moment.

proc now(t: typedesc[Moment]): Moment {.inline.}
1

fromNow

Returns moment in time which is equal to current moment + Duration.

proc fromNow(t: typedesc[Moment]; a: Duration): Moment {.inline.}
1

Templates


transport