v2 / examples / eventbus / modules / some_module / some_module.v
32 lines · 26 sloc · 609 bytes · 008aaad99981918c51194d7aaaaaccb4c258f244
Raw
1module some_module
2
3import eventbus
4
5const eb = eventbus.new[string]()
6
7pub struct Duration {
8pub:
9 hours int
10}
11
12pub struct EventMetadata {
13pub:
14 message string
15}
16
17pub fn do_work() {
18 duration := Duration{10}
19 for i in 0 .. 10 {
20 println('working...')
21 if i == 5 {
22 event_metadata := &EventMetadata{'Iteration ' + i.str()}
23 eb.publish('event_foo', duration, event_metadata)
24 eb.publish('event_bar', duration, event_metadata)
25 }
26 }
27 eb.publish('event_baz', &Duration{42}, &EventMetadata{'Additional data at the end.'})
28}
29
30pub fn get_subscriber() eventbus.Subscriber[string] {
31 return *eb.subscriber
32}
33