v/examples/eventbus/modules/some_module/some_module.v

35 lines
646 B
V
Raw Normal View History

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