Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fiber ¶
type Fiber struct {
// Data is an arbitrary user-data slot for attaching per-fiber state.
Data any
// contains filtered or unexported fields
}
Fiber is a cooperative unit of execution managed by a Scheduler. Each fiber runs in its own goroutine but only one fiber is logically active at a time. Fibers yield control explicitly via Block or SwitchToNew.
type Scheduler ¶
type Scheduler struct {
// contains filtered or unexported fields
}
Scheduler implements cooperative (non-preemptive) scheduling of fibers. At most one fiber is active at any time; fibers yield control by calling Block or SwitchToNew. Blocking operations run concurrently in their fiber's goroutine, allowing I/O parallelism while maintaining single-threaded logical execution for non-blocking code.
func (*Scheduler) Block ¶
Block suspends the active fiber, allowing other fibers to run, while fn executes concurrently in this fiber's goroutine. When fn returns, the fiber is re-enqueued and waits to be re-scheduled. The context passed to fn is derived from ctx and can be cancelled via CancelBlocked.
func (*Scheduler) CancelBlocked ¶
func (s *Scheduler) CancelBlocked()
CancelBlocked cancels the context of every currently blocked fiber. This causes the context passed to each Block callback to be cancelled, which should cause the callback to return promptly.
func (*Scheduler) ForEachFiber ¶
ForEachFiber calls h for every fiber in the scheduler: the active fiber (if any), all ready fibers, and all blocked fibers.
func (*Scheduler) NewFiber ¶
NewFiber creates a new fiber that will execute fn when started. The fiber is not started until it is passed to SwitchToNew or Run.
func (*Scheduler) Run ¶
Run starts the scheduler loop with the given fiber as the initial fiber. It blocks until all fibers (active, ready, and blocked) have terminated.
func (*Scheduler) SwitchToNew ¶
SwitchToNew parks the active fiber in the ready queue and immediately starts f. The caller resumes when the scheduler re-schedules it (FIFO).