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

eventbus: make it usable and add README

This commit is contained in:
Abdullah Atta
2019-11-24 16:27:50 +05:00
committed by Alexander Medvednikov
parent a74f4a661d
commit d4ae39348f
6 changed files with 210 additions and 19 deletions

1
examples/eventbus/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
eventbus

View File

@@ -0,0 +1,16 @@
module main
import (
some_module
eventbus
)
fn main(){
mut sub := some_module.get_subscriber()
sub.subscribe("error", on_error)
some_module.do_work()
}
fn on_error(p eventbus.Params) {
println(p.get_string("error"))
}

View File

@@ -0,0 +1,27 @@
module some_module
import (
eventbus
)
const (
eb = eventbus.new()
)
pub fn do_work(){
mut params := eventbus.Params{}
for i in 0..20 {
println("working...")
if i == 15 {
params.put_string("error", "CRASH!!")
eb.publish("error", params)
eb.publish("error", params)
return
}
}
}
pub fn get_subscriber() eventbus.Subscriber {
return eb.subscriber
}