Skip to content

Commit

Permalink
ci: fix ./v -W examples/eventbus/eventbus.v after 551a065 (todo: pe…
Browse files Browse the repository at this point in the history
…rhaps it should be reverted completely)
  • Loading branch information
spytheman committed Sep 19, 2023
1 parent 77219de commit 350a8d3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions vlib/eventbus/eventbus.v
Expand Up @@ -64,13 +64,15 @@ pub fn (eb &EventBus[T]) has_subscriber(name T) bool {
return eb.registry.check_subscriber(name)
}

const dedup_buffer_len = 20

// publish publish an event with provided Params & name.
fn (mut pb Publisher[T]) publish(name T, sender voidptr, args voidptr) {
// println('Publisher.publish(name=${name} sender=${sender} args=${args})')
mut handled_receivers := [20]voidptr{} // handle duplicate bugs TODO fix properly + perf
mut handled_receivers := unsafe { [eventbus.dedup_buffer_len]voidptr{} } // handle duplicate bugs TODO fix properly + perf
// is_key_down := name == 'on_key_down'
mut j := 0
for i, event in pb.registry.events {
for event in pb.registry.events {
if event.name == name {
// if is_key_down {
if event.receiver in handled_receivers {
Expand All @@ -81,7 +83,7 @@ fn (mut pb Publisher[T]) publish(name T, sender voidptr, args voidptr) {
event.handler(event.receiver, args, sender)
// handled_receivers << event.receiver
handled_receivers[j] = event.receiver
j++
j = (j + 1) % eventbus.dedup_buffer_len
}
}
pb.registry.events = pb.registry.events.filter(!(it.name == name && it.once))
Expand Down

0 comments on commit 350a8d3

Please sign in to comment.