Utilities related to event-subsetting
EventSender |
This structure is coded to achieve event-subsetting. Receivers in Rust are blocking. One cannot
listen to multiple receivers at the same time except by using try_recv which again is bad for
the same reasons spin-lock based on some sleep is bad (wasting cycles, 50% efficienct on an
average etc.). Consider a module that listens to signals from various other modules. Different
modules want to talk to this one. So one solution is make a common event set and all senders
(registered in all the interested modules) send events from the same set. This is bad for
maintenance. Wrong modules might use events not expected to originate from them since it is just
one huge event-set. Thus there is a need of event-subsetting and distribute this module-wise so
we prevent modules from using wrong events, completely by design and code-mechanics. Also we
don't want to spawn threads listening to different receivers (which could force to share
ownership and is anyway silly otherwise too). This is what EventSender helps to salvage. A
simple mechanism that does what a skip-list in linked list does. It brings forth a concept of
an Umbrella event-category and an event subset. The creator of EventSender hard-codes the
category for different observers. Each category only links to a particular event-subset and
type information of this is put into EventSender to during it's construction. Thus when
distributed, the modules cannot cheat (do the wrong thing) by trying to fire an event they are
not permitted to. Also a single thread listens to many receivers. All problems solved.
|