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