src/threadButler/channelHub

Source   Edit  

Defines utilities for interacting with a ChannelHub. Further utilities may be generated by codegen.

A ChannelHub is a table of all Channels to all thread-servers in an application. It contains one Channel per registered Thread through which one specific "Message"-object variant can be sent. The channel for a given Message-object-variant is stored with (and can thus be retrieved with) data inferred from the object-variant.

Types

ChannelHub = object
  channels*: Table[pointer, pointer]
Source   Edit  
ChannelHubError = object of KeyError
Source   Edit  

Consts

SEND_PROC_NAME = "sendMsgToChannel"
Source   Edit  

Procs

proc addChannel[Msg](hub: var ChannelHub; t: typedesc[Msg]; capacity: int)
Instantiates and opens a Channel to hub specifically for type Msg. This associates it with Msg. Source   Edit  
proc destroyChannel[Msg](chan: var Channel[Msg])
Source   Edit  
proc getChannel[Msg](hub`gensym0: ChannelHub; t`gensym0: typedesc[Msg]): var Channel[
    Msg] {....raises: [ChannelHubError].}
Fetches the Channel associated with Msg from hub. Source   Edit  
proc readMsg[Msg](hub: ChannelHub; resp: typedesc[Msg]): Option[Msg]
Reads message from the Channel associated with Msg. This is non-blocking. Source   Edit  
proc sendMsgToChannel[Msg](hub: ChannelHub; msg: sink Msg): bool {.
    ...raises: [ChannelHubError].}
Sends a message through the Channel associated with Msg. This is non-blocking. Returns bool stating if sending was successful. Source   Edit