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()
|
|
|
|
)
|
|
|
|
|
2019-12-18 08:16:33 +03:00
|
|
|
pub struct Work {
|
2021-02-22 19:44:15 +03:00
|
|
|
pub:
|
2019-12-18 08:16:33 +03:00
|
|
|
hours int
|
|
|
|
}
|
|
|
|
|
2021-02-22 19:44:15 +03:00
|
|
|
pub struct MyError {
|
|
|
|
pub:
|
2020-01-22 19:41:08 +03:00
|
|
|
message string
|
|
|
|
}
|
|
|
|
|
2021-04-20 17:16:35 +03:00
|
|
|
pub fn do_work() {
|
2019-12-18 08:16:33 +03:00
|
|
|
work := Work{20}
|
2021-04-20 17:16:35 +03:00
|
|
|
for i in 0 .. 20 {
|
|
|
|
println('working...')
|
2019-11-24 14:27:50 +03:00
|
|
|
if i == 15 {
|
2021-04-20 17:16:35 +03:00
|
|
|
error := &MyError{'There was an error.'}
|
|
|
|
some_module.eb.publish('error', work, error)
|
|
|
|
some_module.eb.publish('error', work, error)
|
2019-11-24 14:27:50 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
}
|