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

Custom events failed to execute #68

Open
arduanov opened this issue May 7, 2024 · 1 comment
Open

Custom events failed to execute #68

arduanov opened this issue May 7, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@arduanov
Copy link

arduanov commented May 7, 2024

System (please complete the following information):

  • OS: macOS
  • GO Version: 1.22.1
  • Pkg Version: 1.1.2

Describe the bug

panic: interface conversion: event.Event is *event.BasicEvent, not *main.MmyEvent

To Reproduce

package main

import (
	"fmt"

	"github.com/gookit/event"
)

type MyEvent struct {
	event.BasicEvent
	customData string
}

func (e *MyEvent) CustomData() string {
	return e.customData
}

func main() {
	e := &MyEvent{customData: "hello"}
	e.SetName("e1")
	event.AddEvent(e)

	// add listener
	event.On("e1", event.ListenerFunc(func(e event.Event) error {
		fmt.Printf("custom Data: %s\n", e.(*MyEvent).CustomData())
		return nil
	}))

	// trigger
	event.Fire("e1", nil)
}
panic: interface conversion: event.Event is *event.BasicEvent, not *main.MyEvent

goroutine 1 [running]:
main.main.func1({0x102873790?, 0x140001102d0?})
        /Users/m.arduanov/go/src/tt/main.go:25 +0xa4
github.com/gookit/event.ListenerFunc.Handle(0x1400012e048?, {0x102873790?, 0x140001102d0?})
        /Users/m.arduanov/go/pkg/mod/github.com/gookit/[email protected]/listener.go:18 +0x34
github.com/gookit/event.(*Manager).fireSimpleMode(0x14000136000, {0x102828f15, 0x2}, {0x102873790, 0x140001102d0})
        /Users/m.arduanov/go/pkg/mod/github.com/gookit/[email protected]/manager.go:269 +0xb4
github.com/gookit/event.(*Manager).FireEvent(0x14000136000, {0x102873790, 0x140001102d0})
        /Users/m.arduanov/go/pkg/mod/github.com/gookit/[email protected]/manager.go:243 +0x12c
github.com/gookit/event.(*Manager).fireByName(0x14000136000, {0x102828f15?, 0x2?}, 0x0, 0x0)
        /Users/m.arduanov/go/pkg/mod/github.com/gookit/[email protected]/manager.go:221 +0x1d0
github.com/gookit/event.(*Manager).Fire(...)
        /Users/m.arduanov/go/pkg/mod/github.com/gookit/[email protected]/manager.go:173
github.com/gookit/event.Fire(...)
        /Users/m.arduanov/go/pkg/mod/github.com/gookit/[email protected]/std.go:67
main.main()
        /Users/m.arduanov/go/src/tt/main.go:30 +0xd0
exit status 2

Expected behavior

Listener get MyEvent with CustomData()

@arduanov
Copy link
Author

arduanov commented May 7, 2024

but FireEvent works perfect

event.FireEvent(e)

@inhere inhere added the bug Something isn't working label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants