Initial project import
This commit is contained in:
commit
23f2d29e32
11957 files changed
+1754577
No files matched your search
@@ -0,0 +1,33 @@
|
||||
module main
|
||||
|
||||
import some_module
|
||||
|
||||
struct Receiver {
|
||||
mut:
|
||||
ok bool
|
||||
}
|
||||
|
||||
fn main() {
|
||||
mut sub := some_module.get_subscriber()
|
||||
r := Receiver{}
|
||||
sub.subscribe_method('event_foo', on_foo, r)
|
||||
sub.subscribe('event_bar', on_bar)
|
||||
sub.subscribe('event_baz', on_baz)
|
||||
|
||||
println('Receiver ok: ' + r.ok.str())
|
||||
some_module.do_work()
|
||||
println('Receiver ok: ' + r.ok.str())
|
||||
}
|
||||
|
||||
fn on_foo(mut receiver Receiver, e &some_module.EventMetadata, _sender voidptr) {
|
||||
receiver.ok = true
|
||||
println('on_foo :: ' + e.message)
|
||||
}
|
||||
|
||||
fn on_bar(_receiver voidptr, e &some_module.EventMetadata, _sender voidptr) {
|
||||
println('on_bar :: ' + e.message)
|
||||
}
|
||||
|
||||
fn on_baz(_receiver voidptr, _event voidptr, d &some_module.Duration) {
|
||||
println('on_baz :: ' + d.hours.str())
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
module some_module
|
||||
|
||||
import eventbus
|
||||
|
||||
const eb = eventbus.new[string]()
|
||||
|
||||
pub struct Duration {
|
||||
pub:
|
||||
hours int
|
||||
}
|
||||
|
||||
pub struct EventMetadata {
|
||||
pub:
|
||||
message string
|
||||
}
|
||||
|
||||
pub fn do_work() {
|
||||
duration := Duration{10}
|
||||
for i in 0 .. 10 {
|
||||
println('working...')
|
||||
if i == 5 {
|
||||
event_metadata := &EventMetadata{'Iteration ' + i.str()}
|
||||
eb.publish('event_foo', duration, event_metadata)
|
||||
eb.publish('event_bar', duration, event_metadata)
|
||||
}
|
||||
}
|
||||
eb.publish('event_baz', &Duration{42}, &EventMetadata{'Additional data at the end.'})
|
||||
}
|
||||
|
||||
pub fn get_subscriber() eventbus.Subscriber[string] {
|
||||
return *eb.subscriber
|
||||
}
|
||||
Reference in new issue
Block a user