1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

improve eventbus

This commit is contained in:
Abdullah Atta
2020-01-22 21:41:08 +05:00
committed by Alexander Medvednikov
parent 136c469ef7
commit 43ba6766ba
6 changed files with 115 additions and 274 deletions

View File

@@ -2,7 +2,6 @@ module main
import (
some_module
eventbus
)
fn main(){
@@ -11,8 +10,6 @@ fn main(){
some_module.do_work()
}
fn on_error(sender voidptr, p eventbus.Params) {
work := *(*some_module.Work(sender))
println(work.hours)
println(p.get_string("error"))
fn on_error(sender voidptr, e &some_module.Error) {
println(e.message)
}

View File

@@ -13,19 +13,22 @@ pub struct Work {
hours int
}
pub struct Error {
pub:
message string
}
pub fn do_work(){
work := Work{20}
mut params := eventbus.Params{}
for i in 0..20 {
println("working...")
if i == 15 {
params.put_string("error", "CRASH!!")
eb.publish("error", work, params)
eb.publish("error", work, params)
error := &Error{"There was an error."}
eb.publish("error", work, error)
eb.publish("error", work, error)
return
}
}
}
pub fn get_subscriber() eventbus.Subscriber {