2019-11-24 12:27:50 +01:00
|
|
|
module main
|
|
|
|
|
2020-04-26 13:49:31 +02:00
|
|
|
import some_module
|
2019-11-24 12:27:50 +01:00
|
|
|
|
2022-02-26 08:50:44 +01:00
|
|
|
struct Receiver {
|
|
|
|
mut:
|
|
|
|
ok bool
|
|
|
|
}
|
|
|
|
|
2021-04-20 16:16:35 +02:00
|
|
|
fn main() {
|
2019-11-24 12:27:50 +01:00
|
|
|
mut sub := some_module.get_subscriber()
|
2022-02-26 08:50:44 +01:00
|
|
|
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())
|
2019-11-24 12:27:50 +01:00
|
|
|
some_module.do_work()
|
2022-02-26 08:50:44 +01:00
|
|
|
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)
|
2019-11-24 12:27:50 +01:00
|
|
|
}
|
|
|
|
|
2022-02-26 08:50:44 +01:00
|
|
|
fn on_baz(receiver voidptr, event voidptr, d &some_module.Duration) {
|
|
|
|
println('on_baz :: ' + d.hours.str())
|
2019-12-01 08:33:26 +01:00
|
|
|
}
|