TudbuT
adabbe0418
=<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
44 lines
804 B
Text
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
|
|
}
|
|
}
|
|
}
|