rumpk/core/bus.nim

32 lines
742 B
Nim

# MARKUS MAIWALD (ARCHITECT) | VOXIS FORGE (AI)
# RUMPK CORE // BUS
# The Global Message Bus for Nexus Channels.
#
# This registry allows Fibers to discover Channels by SipHash ID.
{.push stackTrace: off, lineTrace: off.}
import channel
const MAX_CHANNELS = 32
type
Bus* = object
channels*: array[MAX_CHANNELS, ptr Channel[64]] # Fixed size for now
count*: int
var global_bus*: Bus
proc register*(chan: ptr Channel[64]) =
if global_bus.count < MAX_CHANNELS:
global_bus.channels[global_bus.count] = chan
inc global_bus.count
proc findChannel*(id: ChannelID): ptr Channel[64] =
for i in 0..<global_bus.count:
if global_bus.channels[i].id == id:
return global_bus.channels[i]
return nil
{.pop.}