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

examples: improve the sendbus example (#13604)

This commit is contained in:
Mihai Galos
2022-02-26 08:50:44 +01:00
committed by GitHub
parent 0d9792bdf2
commit 4215bb125c
2 changed files with 35 additions and 15 deletions

View File

@ -6,27 +6,27 @@ const (
eb = eventbus.new()
)
pub struct Work {
pub struct Duration {
pub:
hours int
}
pub struct MyError {
pub struct EventMetadata {
pub:
message string
}
pub fn do_work() {
work := Work{20}
for i in 0 .. 20 {
duration := Duration{10}
for i in 0 .. 10 {
println('working...')
if i == 15 {
error := &MyError{'There was an error.'}
some_module.eb.publish('error', work, error)
some_module.eb.publish('error', work, error)
return
if i == 5 {
event_metadata := &EventMetadata{'Iteration ' + i.str()}
some_module.eb.publish('event_foo', duration, event_metadata)
some_module.eb.publish('event_bar', duration, event_metadata)
}
}
some_module.eb.publish('event_baz', &Duration{42}, &EventMetadata{'Additional data at the end.'})
}
pub fn get_subscriber() eventbus.Subscriber {