| 1 | module some_module |
| 2 | |
| 3 | import eventbus |
| 4 | |
| 5 | const eb = eventbus.new[string]() |
| 6 | |
| 7 | pub struct Duration { |
| 8 | pub: |
| 9 | hours int |
| 10 | } |
| 11 | |
| 12 | pub struct EventMetadata { |
| 13 | pub: |
| 14 | message string |
| 15 | } |
| 16 | |
| 17 | pub 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 | |
| 30 | pub fn get_subscriber() eventbus.Subscriber[string] { |
| 31 | return *eb.subscriber |
| 32 | } |
| 33 | |