Closed b1conrad closed 1 year ago
Let's settle on the first alternative. For one, it requires less code from the KRL programmer. For another, it is a lot simpler to implement.
A note on host
. The first alternative is also better here, because if the subscription has a "host"
key then that value would be the domain:port of the other pico and so is readily available for the event:send
to use.
In the base (current) functionality, the KRL programmer has the double burden of
Both of those are resolved in a subscription Map, as the keys
"Tx"
"Tx_host"
Notice that in the test rulesets, the first alternative is tested by test.event_send.sub_map
while the second would have been tested by test.event_send.sub
and they are listed in the opposite order in UnitTest/event:send. Sorry about that.
event:send
the action expects a Map and an optionalhost
. Together, these allow it to reach the pico that is to receive the event. In particular, it needs to know the ECI to be used to attract the attention of that pico, and this is currently given explicitly by a key"eci"
in the Map.While a ruleset might have hold of an ECI for some other pico, it is more often the case that it holds a subscription to that pico. A subscription is itself represented by a Map, and the ECI to use for the other pico is held in that Map with the key
"Tx"
. So, if we have a subscription, bound to the namemy_subs
then we can do anevent:send
like this:This issue suggests a couple of shorthand, convenience, alternatives:
Alternative the first:
This would be useful when the programmer has already obtained, or is storing, the subscription.
Alternative the second:
This would be useful when the programmer is hanging on the a subscription's identifier, as in
These alternatives will need to be implemented by changes to pico-engine/packages/pico-engine-core/src/modules/event.ts
In the spirit of Test-driven development, failing tests are provided at https://b1conrad.github.io/KRL-experiments/UnitTest/event_send/