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

RemoveListener not support closure function #9

Closed
RelicOfTesla opened this issue Mar 24, 2021 · 1 comment · Fixed by #41 or #42
Closed

RemoveListener not support closure function #9

RelicOfTesla opened this issue Mar 24, 2021 · 1 comment · Fixed by #41 or #42
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@RelicOfTesla
Copy link
Contributor

RelicOfTesla commented Mar 24, 2021

func makeFn(a int) event.ListenerFunc {
	return func(e event.Event) error {
		fmt.Println(a)
		return nil
	}
}
func main() {
	evBus := event.NewManager("")
	f1 := makeFn(11)
	evBus.On("evt1", f1)
	f2 := makeFn(22)
	evBus.On("evt1", f2)
	evBus.RemoveListener("evt1", f1) // DON'T REMOVE ALL !!!
	evBus.MustFire("evt1", event.M{"arg0": "val0", "arg1": "val1"})
}
@inhere inhere added the bug Something isn't working label Mar 25, 2021
@inhere inhere added the good first issue Good for newcomers label Jun 4, 2021
@intrntbrn
Copy link

intrntbrn commented Oct 5, 2021

The issue is that "%p" is equal for f1 and f2.

You can work around this issue by using new:

f1 := makeFn(11)
l := new(event.ListenerFunc)
*l = f1
evBus.On("evt1", l)
f2 := makeFn(22)
evBus.On("evt1", f2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
3 participants