Skip to content

Commit

Permalink
Typed signatures for event handlers.
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Patrin <ppatrin@nvidia.com>
  • Loading branch information
pavelpatrin committed Aug 5, 2024
1 parent e836e54 commit e88c7a0
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ func (em *events) Subscribe(name string, handlerFn any) {

// Register event handler function.
if handlerType.NumIn() == 1 && handlerType.In(0) == anySliceType {
// Register a function that accepts a variable number of any arguments.
em.events[name] = append(em.events[name], func(event Event) error {
return em.callAnyVarHandler(handlerValue, event.Args())
})
} else {
// Register a function that accepts concrete argument types.
em.events[name] = append(em.events[name], func(event Event) error {
return em.callTypedHandler(handlerValue, event.Args())
})
Expand Down

0 comments on commit e88c7a0

Please sign in to comment.