chronos/internal/raisesfutures

Source   Edit  

Types

InternalRaisesFuture[T; E] = ref object of Future[T]
  when E is void:
  else:

Future with a tuple of possible exception types eg InternalRaisesFuturevoid, (ValueError, OSError)

This type gets injected by async: (raises: ...) and similar utilities and should not be used manually as the internal exception representation is subject to change in future chronos versions.

Source   Edit  

Procs

func error[T](future: InternalRaisesFuture[T, void]): ref CatchableError {.
    ...raises: [], raises: [].}
Source   Edit  
func failed[T](future: InternalRaisesFuture[T, void]): bool {.inline, ...raises: [].}
Determines whether future finished with an error. Source   Edit  
proc getRaisesTypes(raises: NimNode): NimNode {....raises: [], tags: [],
    forbids: [].}
Source   Edit  
proc isNoRaises(n: NimNode): bool {.compileTime, ...raises: [], tags: [],
                                    forbids: [].}
Source   Edit  
proc makeNoRaises(): NimNode {.compileTime, ...raises: [], tags: [], forbids: [].}
Source   Edit  
func readError[T](future: InternalRaisesFuture[T, void]): ref CatchableError {.
    ...raises: [ValueError], raises: [].}
Source   Edit  

Macros

macro checkRaises[T: CatchableError](future: InternalRaisesFuture;
                                     raises: typed; error: ref T;
                                     warn: static bool = true): untyped {..}

Generate code that checks that the given error is compatible with the raises restrictions of future.

This check is done either at compile time or runtime depending on the information available at compile time - in particular, if the raises inherit from error, we end up with the equivalent of a downcast which raises a Defect if it fails.

Source   Edit  
macro prepend(tup: typedesc; typs: varargs[typed]): typedesc {..}
Source   Edit  
macro Raising[T](F: typedesc[Future[T]]; E: typed): untyped {..}

Given a Future type instance, return a type storing {.raises.} information

Note; this type may change in the future

Source   Edit  
macro remove(tup: typedesc; typs: varargs[typed]): typedesc {..}
Source   Edit  
macro union(tup0: typedesc; tup1: typedesc): typedesc {..}
Join the types of the two tuples deduplicating the entries Source   Edit  

Templates

template init[T, E](F: type InternalRaisesFuture[T, E];
                    fromProc: static[string] = ""): F:type {..}

Creates a new pending 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.

Source   Edit  
template init[T, E](F: type InternalRaisesFuture[T, E];
                    fromProc: static[string] = ""; flags: static[FutureFlags]): F:type {..}

Creates a new pending 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.

Source   Edit