2019-11-24 12:27:50 +01:00
|
|
|
module some_module
|
|
|
|
|
2020-04-26 13:49:31 +02:00
|
|
|
import eventbus
|
2019-11-24 12:27:50 +01:00
|
|
|
|
|
|
|
const (
|
|
|
|
eb = eventbus.new()
|
|
|
|
)
|
|
|
|
|
2022-02-26 08:50:44 +01:00
|
|
|
pub struct Duration {
|
2021-02-22 17:44:15 +01:00
|
|
|
pub:
|
2019-12-18 06:16:33 +01:00
|
|
|
hours int
|
|
|
|
}
|
|
|
|
|
2022-02-26 08:50:44 +01:00
|
|
|
pub struct EventMetadata {
|
2021-02-22 17:44:15 +01:00
|
|
|
pub:
|
2020-01-22 17:41:08 +01:00
|
|
|
message string
|
|
|
|
}
|
|
|
|
|
2021-04-20 16:16:35 +02:00
|
|
|
pub fn do_work() {
|
2022-02-26 08:50:44 +01:00
|
|
|
duration := Duration{10}
|
|
|
|
for i in 0 .. 10 {
|
2021-04-20 16:16:35 +02:00
|
|
|
println('working...')
|
2022-02-26 08:50:44 +01:00
|
|
|
if i == 5 {
|
|
|
|
event_metadata := &EventMetadata{'Iteration ' + i.str()}
|
|
|
|
some_module.eb.publish('event_foo', duration, event_metadata)
|
|
|
|
some_module.eb.publish('event_bar', duration, event_metadata)
|
2019-11-24 12:27:50 +01:00
|
|
|
}
|
|
|
|
}
|
2022-02-26 08:50:44 +01:00
|
|
|
some_module.eb.publish('event_baz', &Duration{42}, &EventMetadata{'Additional data at the end.'})
|
2019-11-24 12:27:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_subscriber() eventbus.Subscriber {
|
2021-04-20 16:16:35 +02:00
|
|
|
return *some_module.eb.subscriber
|
2019-12-01 08:33:26 +01:00
|
|
|
}
|