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

Panic on event Publishing #102

Closed
joelschutz opened this issue Apr 21, 2023 · 1 comment · Fixed by #103
Closed

Panic on event Publishing #102

joelschutz opened this issue Apr 21, 2023 · 1 comment · Fixed by #103

Comments

@joelschutz
Copy link
Contributor

If you try to publish an Event that no handler is listening the program panic since no event bus is found.

How to Reproduce

Create a new event and try to publish to it.

type EnemyKilled struct {
	EnemyID int
}

var EnemyKilledEvent = events.NewEventType[*EnemyKilled]()

func TestEvents(t *testing.T) {
	w := donburi.NewWorld()
	EnemyKilledEvent.Publish(w, &EnemyKilled{EnemyID: 1})
}

Problem

It makes sense to only initialize a bus if there is a handler to react to it, but in a game you often need to add or remove subscribers dymanically. Attaching the bus initialization to the Subscribe method makes it difficult since all the system depends on that first subscription.

joelschutz added a commit to joelschutz/donburi that referenced this issue Apr 21, 2023
@joelschutz joelschutz mentioned this issue Apr 21, 2023
yohamta pushed a commit that referenced this issue Apr 22, 2023
@yohamta
Copy link
Owner

yohamta commented Apr 22, 2023

Hi @joelschutz , Thank you so much for submitting such a great issue and PR! It has been released as version 1.3.7.

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 a pull request may close this issue.

2 participants