Skip to content

Commit

Permalink
更新
Browse files Browse the repository at this point in the history
  • Loading branch information
deatil committed Jul 29, 2024
1 parent 5762e14 commit 253020f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion events/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Event struct {
func (this *Event) Observe(observer any, prefix string, sort int) *Event {
observerKind := reflect.TypeOf(observer).Kind()
if observerKind != reflect.Struct && observerKind != reflect.Pointer {
return this
panic("go-events: observe input type error")
}

if ob, ok := observer.(ISubscribePrefix); ok {
Expand Down
27 changes: 27 additions & 0 deletions events/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -775,3 +775,30 @@ func Test_Struct_fail_5(t *testing.T) {
action.Trigger("Test_Struct_fail_5", data1)
}

type TestEventObserveOn struct{}

func (this TestEventObserveOn) OnTestEvent(data any) {
testEventRes["TestEventObserveOn"] = data
}

func Test_EventObserveOn(t *testing.T) {
eq := assertDeepEqualT(t)

defer func() {
if e := recover(); e != nil {
err := fmt.Sprintf("%v", e)

check := "go-events: observe input type error"
eq(err, check, "Struct failed 5")
}
}()

action := NewAction()
action.Subscribe(TestEventObserveOn{})
action.Subscribe("test")

data1 := "init77889"
action.Trigger("TestEvent", data1)

eq(testEventRes["TestEventObserveOn"], "init77889", "Test_EventObserveOn")
}

0 comments on commit 253020f

Please sign in to comment.