Documentation ¶
Index ¶
Constants ¶
const (
ErrTypeHandlerCanceled = "reactor.handle_canceled"
)
Variables ¶
var (
ErrHandlerCanceled = errors.New("reactor handle not run for canceling, the Reactor has been stopped")
)
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Reactor)
func WithContext ¶
WithContext defines a context for controlling the Reactor in another way except Start/Stop method.
type Reactor ¶
type Reactor struct {
// contains filtered or unexported fields
}
Reactor provides a "reactor" design mode for function called. It's similar to event loop, each function submit to the Reactor is an event, and Reactor calls the function as event process. If you need to process many functions calls having concurrent or sync lock scenes, Reactor will help you make each function call into an ordering queue and calls them one by one, which would not required to consider the sync lock or concurrent question. It's like a goroutine pool with single goroutine.See example for more usages and details.
func NewReactor ¶
func (*Reactor) Push ¶
Push will insert the handler to Reactor's queue and return immediately. If the Reactor has benn stopped, it will return ErrInvalidStatus error with typed ErrTypeInvalidStatus.
func (*Reactor) PushPriority ¶
PushPriority is the same as Push, but the Handler is higher priority than Push.
func (*Reactor) Send ¶
Send will insert the handler to Reactor's queue and wait for the Handler run completed. If the Reactor has benn stopped, it will return ErrInvalidStatus error with typed ErrTypeInvalidStatus. If the Handler inserted to the queue and waiting for run, but the Reactor is Stop, it will return ErrHandlerCanceled error with ErrTypeHandlerCanceled.
func (*Reactor) SendPriority ¶
SendPriority is the same as Send, but the Handler is higher priority than Send.
func (*Reactor) Start ¶
func (r *Reactor) Start()
Start is required to call before Push or Send Handler to the Reactor. It will be called with Stop in pair.