🐛 fix: fix custom events failed to execute. see issues #68

This commit is contained in:
inhere
2025-08-25 13:14:00 +08:00
parent dc11518436
commit 2139003c0e
3 changed files with 30 additions and 7 deletions

View File

@@ -207,12 +207,6 @@ func (e *BasicEvent) SetName(name string) *BasicEvent {
return e
}
// Clone new instance
func (e *BasicEvent) Clone() Event {
var cp = *e
return &cp
}
// SetData set data to the event
func (e *BasicEvent) SetData(data M) Event {
if data != nil {

View File

@@ -118,5 +118,6 @@ func TestEvent(t *testing.T) {
e1 := &event.BasicEvent{}
e1.Set("k", "v")
assert.Equal(t, "v", e1.Get("k"))
assert.NotEmpty(t, e1.Clone())
// assert.NotEmpty(t, e1.Clone())
assert.NotEmpty(t, e1.Context())
}

View File

@@ -162,6 +162,34 @@ func TestIssues_67(t *testing.T) {
assert.Eq(t, total, counter)
}
type MyEventI68 struct {
event.BasicEvent
customData string
}
func (e *MyEventI68) CustomData() string {
return e.customData
}
// https://github.com/gookit/event/issues/68 Custom events failed to execute
func TestIssues_68(t *testing.T) {
e := &MyEventI68{customData: "hello"}
e.SetName("e1")
defer event.Reset()
assert.NoErr(t, event.AddEvent(e))
// add listener
event.On("e1", event.ListenerFunc(func(e event.Event) error {
fmt.Printf("custom Data: %s\n", e.(*MyEventI68).CustomData())
return nil
}))
// trigger
err, e2 := event.Fire("e1", nil)
assert.NoErr(t, err)
assert.Eq(t, "e1", e2.Name())
}
// https://github.com/gookit/event/issues/78
// It is expected to support event passing context, timeout control, and log trace passing such as trace ID information.
// 希望事件支持通过上下文超时控制和日志跟踪传递例如跟踪ID信息。