init repo

This commit is contained in:
2026-10-20 18:53:09 +08:00
commit 466b0ea05d
13 changed files with 1877 additions and 0 deletions

25
dispatcher.go Normal file
View File

@@ -0,0 +1,25 @@
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()
}