PUBLISH and SUBSCRIBE statements
- Last Updated: August 7, 2023
- 1 minute read
- OpenEdge
- Version 13.0
- Documentation
When you have multiple procedures running in a session, you might want them to communicate with each other without being strictly bound to each other. In other words, one procedure might want to send a message to other procedures that are interested in receiving that message without knowing or caring just how many such procedures there are, what their procedure handles are, or what they intend to do with the information. Likewise, a procedure might want to post an interest in receiving a message on a subject without necessarily knowing or caring where the message comes from.
PUBLISH and SUBSCRIBE keywords for
this purpose. One procedure can publish a named event when something of interest happens
and other procedures running in the same session can subscribe to that same event name,
either in a particular procedure handle or anywhere in the session. When the event
occurs, an internal procedure in each subscriber runs. If there are no subscribers, then
nothing happens and no error results. If there are many subscribers, they all get the
message. In effect, a PUBLISH statement amounts to ABL executing this
pseudo-code:
|
The order in which multiple subscribers receive an event is undefined.
Just as with any procedure call, a PUBLISH statement can include one or more
parameters. These are normally INPUT parameters, although under some
circumstances other parameter modes can be useful.