spl/messaging.spl
TudbuT adabbe0418
feat: add messaging, fix: allow tabs, fix: add =<0-5> methods to arrays
=<0-5> is the counterpart to the normal <0-5> methods used for easier indexing into the first few indexes to allow arrays to be used like tuples
2023-04-10 02:26:21 +02:00

44 lines
804 B
Text

"messaging bus, aka event bus"
construct messaging namespace {
Message
Bus
}
construct messaging:Message {
name
content
;
construct { this | with name content this ;
name this:=name
content this:=content
this
}
}
construct messaging:Bus {
subscribers
;
construct { this | with this ;
MicroMap:new this:=subscribers
this
}
subscribe { | with message callable this ;
def entry message this:subscribers:get-or-create-entry =entry
entry:1 null eq if {
List:new entry:=1
}
callable entry:1:push
}
publish { | with message this ;
message gettype messaging:Message eq not if {
message null messaging:Message:new =message
}
def entry message:name this:subscribers:get =entry
entry null eq not if {
{ | with it ;
message it call
} entry:foreach
}
}
}