Event system
Publishing Events
To publish an event, use the event_system::publish
method.
Here’s an example of publishing an event of type AsyaResponse::Ok
with a custom message:
In this example:
AsyaResponse
is an enumeration that defines the type of events.- The event data, such as the
message
, is passed to thepublish
function.
Predefined events
- General response event. Use it for sending messages to the client:
- Hardware status event. Regularly published to notify about the system’s status.
You can define other variants of the AsyaResponse
and HardwareStatus
enums and publish events accordingly.
Subscribing to Events
To subscribe to events, use the event_system::subscribe_once
function.
Here’s an example of how a WebSocket server listens for an AsyaResponse event and sends it to the client:
Event Data Structure
An event can be any variant of an enumeration that implement Debug
and Display
, such as AsyaResponse
. For example:
You can define custom variants and include relevant data for your application.
Good luck, cowboy