2019-11-24 12:27:50 +01:00
|
|
|
module some_module
|
|
|
|
|
2020-04-26 13:49:31 +02:00
|
|
|
import eventbus
|
2019-11-24 12:27:50 +01:00
|
|
|
|
|
|
|
const (
|
|
|
|
eb = eventbus.new()
|
|
|
|
)
|
|
|
|
|
2019-12-18 06:16:33 +01:00
|
|
|
pub struct Work {
|
2021-02-22 17:44:15 +01:00
|
|
|
pub:
|
2019-12-18 06:16:33 +01:00
|
|
|
hours int
|
|
|
|
}
|
|
|
|
|
2021-02-22 17:44:15 +01:00
|
|
|
pub struct MyError {
|
|
|
|
pub:
|
2020-01-22 17:41:08 +01:00
|
|
|
message string
|
|
|
|
}
|
|
|
|
|
2019-11-24 12:27:50 +01:00
|
|
|
pub fn do_work(){
|
2019-12-18 06:16:33 +01:00
|
|
|
work := Work{20}
|
2019-11-24 12:27:50 +01:00
|
|
|
for i in 0..20 {
|
|
|
|
println("working...")
|
|
|
|
if i == 15 {
|
2021-02-22 17:44:15 +01:00
|
|
|
error := &MyError{"There was an error."}
|
2020-01-22 17:41:08 +01:00
|
|
|
eb.publish("error", work, error)
|
|
|
|
eb.publish("error", work, error)
|
2019-11-24 12:27:50 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_subscriber() eventbus.Subscriber {
|
2020-07-29 21:40:43 +02:00
|
|
|
return *eb.subscriber
|
2019-12-01 08:33:26 +01:00
|
|
|
}
|