26 lines
868 B
Go
26 lines
868 B
Go
package actor
|
|
|
|
// Dispatcher chooses where a mailbox's entire drain task executes. Schedule
|
|
// may run the task inline or asynchronously. It must accept every task, execute
|
|
// it exactly once eventually, and must not reject, silently discard, or panic.
|
|
// Schedule must be safe for concurrent calls when shared by actors. The actor
|
|
// does not provide a fallback for a dispatcher that violates this contract.
|
|
type Dispatcher interface {
|
|
Schedule(task func())
|
|
}
|
|
|
|
// DispatcherFunc adapts a scheduling function to Dispatcher. A nil function is
|
|
// rejected by New when supplied through WithDispatcher.
|
|
type DispatcherFunc func(task func())
|
|
|
|
// Schedule delegates to f. The function must satisfy the Dispatcher contract.
|
|
func (f DispatcherFunc) Schedule(task func()) {
|
|
f(task)
|
|
}
|
|
|
|
type inlineDispatcher struct{}
|
|
|
|
func (inlineDispatcher) Schedule(task func()) {
|
|
task()
|
|
}
|