yao/event/option.go
Max fd24e31912 Update Makefile for enhanced testing and add new event documentation
- Modify unit test commands in the Makefile to include additional skip patterns for memory leak tests, improving test coverage and accuracy.
- Expand benchmark and memory leak detection to include the event module, ensuring comprehensive testing across all components.
- Add new design and TODO documentation files for the event module to facilitate future development.
2026-02-23 12:18:13 +08:00

51 lines
1.5 KiB
Go

package event
import "github.com/yaoapp/yao/event/types"
// MaxWorkers sets the max concurrent worker goroutines for a Handler.
// Default is 512. Workers are fire-and-forget (goroutine ends after task).
func MaxWorkers(n int) types.HandlerOption {
return func(e *types.HandlerEntry) {
e.MaxWorkers = n
}
}
// ReservedWorkers sets the number of workers reserved for Call events.
// Default is 10. Push can use MaxWorkers - Reserved; Call can use MaxWorkers.
func ReservedWorkers(n int) types.HandlerOption {
return func(e *types.HandlerEntry) {
e.ReservedWorkers = n
}
}
// QueueSize sets the per-queue capacity. Default is 8192.
// When a queue is full, Push/Call returns ErrQueueFull immediately.
func QueueSize(n int) types.HandlerOption {
return func(e *types.HandlerEntry) {
e.QueueSize = n
}
}
// Queue sets the queue key for a Push/Call invocation.
// Events with the same queue key are processed serially (FIFO).
func Queue(key string) types.PushOption {
return func(ev *types.Event) {
ev.Queue = key
}
}
// Filter sets a custom filter function for Listen or Subscribe.
// Events that do not pass the filter are skipped.
func Filter(fn func(*types.Event) bool) types.FilterOption {
return func(e *types.FilterEntry) {
e.Filter = fn
}
}
// BufferSize sets the Listener channel buffer size. Default is 8192.
// Only effective for Listen; ignored by Subscribe.
func BufferSize(n int) types.FilterOption {
return func(e *types.FilterEntry) {
e.BufferSize = n
}
}