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