Multiple Event Listeners
Arbitrarily many event listeners can be used in a single job. This is useful when you want to listen to multiple sources to handle job logic
For example, using the example of the PeriodicEventListener
above, we can add a TangleEventListener
to the job:
#[job(
id = 0,
params(x),
result(_),
event_listener(TangleEventListener, PeriodicEventListener::<6000, WebPoller, serde_json::Value, MyContext>), // <-- Register the event listeners here
verifier(evm = "IncredibleSquaringBlueprint")
)]
pub fn hello_event_listener(
x: u64,
context: MyContext,
env: GadgetConfiguration<parking_lot::RawRwLock>,
) -> Result<u64, Infallible> {
Ok(x.saturating_pow(2u32))
}
In this case, both the TangleEventListener
, which is listening to the Tangle network, and the PeriodicEventListener
, which is polling a web server, will be used in parallel to listen for events.