-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.go
39 lines (25 loc) · 838 Bytes
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package batch
import "context"
// type workerHandle interface {
// *Task | []*Task
// }
// type Handler[T workerHandle] interface {
// Handle(context.Context, T) bool
// }
// type Handle[T workerHandle] func(context.Context, T) bool
// func (h Handle[T]) Handle(ctx context.Context, data T) bool {
// return h(ctx, data)
// }
type Handler[T any] interface {
Handle(context.Context, *T, []*T) bool
}
type HandleSingle[T any] func(context.Context, *T) bool
type HandleBatch[T any] func(context.Context, []*T) bool
func (handle HandleSingle[T]) Handle(ctx context.Context, task *T, _ []*T) bool {
return handle(ctx, task)
}
func (handle HandleBatch[T]) Handle(ctx context.Context, _ *T, tasks []*T) bool {
return handle(ctx, tasks)
}
var _ Handler[any] = HandleSingle[any](nil)
var _ Handler[any] = HandleBatch[any](nil)