Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added global dispatcher #3

Merged
merged 1 commit into from Dec 3, 2022
Merged

Added global dispatcher #3

merged 1 commit into from Dec 3, 2022

Conversation

kelindar
Copy link
Owner

@kelindar kelindar commented Dec 3, 2022

For convenience, this PR adds a default global dispatcher that can be used with On() and Emit() package-level functions.

// Subcribe to event A, and automatically unsubscribe at the end
defer event.On(func(e Event) {
    println("(consumer)", e.Data)
})()

// Publish few events
event.Emit(newEventA("event 1"))
event.Emit(newEventA("event 2"))
event.Emit(newEventA("event 3"))

@kelindar kelindar merged commit 51911ab into master Dec 3, 2022
@kelindar kelindar deleted the global branch December 3, 2022 11:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant