async_postgres/async_backend

Search:
Group by:

Async backend configuration module.

Provides unified async framework abstraction for both asyncdispatch and chronos. Select the backend at compile time with -d:asyncBackend=asyncdispatch|chronos. Default backend is asyncdispatch.

Types

AsyncTimeoutError = object of CatchableError
Raised when an async operation times out (chronos-compatible name).
CancelledError = object of CatchableError
Raised when an async operation is cancelled.
Duration = distinct int64
Time interval in nanoseconds. API-compatible with chronos.Duration.
Moment = object
Monotonic timestamp. API-compatible with chronos.Moment.

Consts

hasAsyncDispatch = true
true when the asyncdispatch backend is selected.
hasChronos = false
true when the chronos backend is selected.
ZeroDuration = 0'i64
A zero-length duration.

Procs

proc `$`(d: Duration): string {....raises: [], tags: [], forbids: [].}
proc `+`(a, b: Duration): Duration {.borrow, ...raises: [], tags: [], forbids: [].}
proc `+`(a: Moment; b: Duration): Moment {....raises: [], tags: [], forbids: [].}
proc `-`(a, b: Duration): Duration {.borrow, ...raises: [], tags: [], forbids: [].}
proc `-`(a, b: Moment): Duration {....raises: [], tags: [], forbids: [].}
proc `-`(a: Moment; b: Duration): Moment {....raises: [], tags: [], forbids: [].}
proc `<`(a, b: Duration): bool {.borrow, ...raises: [], tags: [], forbids: [].}
proc `<`(a, b: Moment): bool {....raises: [], tags: [], forbids: [].}
proc `<=`(a, b: Duration): bool {.borrow, ...raises: [], tags: [], forbids: [].}
proc `<=`(a, b: Moment): bool {....raises: [], tags: [], forbids: [].}
proc `==`(a, b: Duration): bool {.borrow, ...raises: [], tags: [], forbids: [].}
proc `>`(a, b: Duration): bool {....raises: [], tags: [], forbids: [].}
proc `>`(a, b: Moment): bool {....raises: [], tags: [], forbids: [].}
proc `>=`(a, b: Duration): bool {....raises: [], tags: [], forbids: [].}
proc `>=`(a, b: Moment): bool {....raises: [], tags: [], forbids: [].}
proc allFutures[T](futures: seq[Future[T]]): Future[void]
Wait for all futures to complete (success or failure).
proc asyncSpawn(fut: Future[void]) {....raises: [Exception], tags: [RootEffect],
                                     forbids: [].}
Fire-and-forget a future. If the future fails with an unhandled exception, a Defect is raised (matching chronos behaviour). The caller is responsible for error handling inside the async proc.
proc cancelAndWait(fut: Future[void]): Future[void] {....stackTrace: false,
    raises: [Exception], tags: [RootEffect], forbids: [].}
Cancel a future and wait for completion. asyncdispatch has no real cancellation; this is a best-effort no-op.
proc cancelTimer(fut: Future[void]) {....raises: [], tags: [], forbids: [].}
No-op: asyncdispatch timers complete harmlessly and are GC'd.
proc completed[T](fut: Future[T]): bool
Check if a future completed successfully (not failed). Chronos-compatible name for finished and not failed.
proc hours(h: int): Duration {....raises: [], tags: [], forbids: [].}
Create a Duration from hours.
proc milliseconds(ms: int): Duration {....raises: [], tags: [], forbids: [].}
Create a Duration from milliseconds.
proc minutes(m: int): Duration {....raises: [], tags: [], forbids: [].}
Create a Duration from minutes.
proc nanoseconds(ns: int): Duration {....raises: [], tags: [], forbids: [].}
Create a Duration from nanoseconds.
proc nanoseconds(ns: int64): Duration {....raises: [], tags: [], forbids: [].}
Create a Duration from nanoseconds.
proc now(T: typedesc[Moment]): Moment
Get the current monotonic timestamp.
proc registerFdReader(fd: cint; cb: proc () {....gcsafe, raises: [].}) {.
    ...raises: [OSError, CatchableError], tags: [], forbids: [].}
Register a file descriptor for read-readiness notifications on the event loop. cb is called whenever the fd becomes readable.
proc scheduleSoon(cb: proc () {....gcsafe, raises: [].}) {....raises: [], tags: [],
    forbids: [].}
Schedule cb to run on the next event loop tick.
proc seconds(s: int): Duration {....raises: [], tags: [], forbids: [].}
Create a Duration from seconds.
proc sleepAsync(d: Duration): Future[void] {....raises: [], tags: [TimeEffect],
    forbids: [].}
Sleep for the given Duration.
proc sleepMsAsync(ms: int): Future[void] {....raises: [], tags: [TimeEffect],
    forbids: [].}
Sleep for ms milliseconds.
proc toMilliseconds(d: Duration): int {....raises: [], tags: [], forbids: [].}
Convert Duration to milliseconds (for asyncdispatch APIs).
proc unregisterFdReader(fd: cint) {....raises: [], tags: [], forbids: [].}
Remove a previously registered read-readiness watcher from the event loop.
proc wait[T](fut: Future[T]; timeout: Duration): Future[T] {....stackTrace: false.}
Wait for a future with a timeout. Raises AsyncTimeoutError on timeout. API-compatible with chronos Future.wait(). Note: asyncdispatch has no cancellation, so the inner future keeps running after timeout. We add a callback to suppress unhandled exception warnings.