mutex

package
v0.0.0-...-68f839e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package mutex provides a task dispatcher that executes tasks sequentially using sync.Mutex. Unlike the queue package, tasks are executed in the same goroutine as the caller, providing synchronous execution with mutex-based serialization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

Dispatcher is used to execute Task sequentially in same goroutine of caller, using sync.Mutex.

func NewDispatcher

func NewDispatcher() *Dispatcher

NewDispatcher creates a new Dispatcher that uses sync.Mutex for task serialization. Tasks are executed synchronously in the caller's goroutine.

func (*Dispatcher) AfterFunc

func (d *Dispatcher) AfterFunc(duration time.Duration, f func()) task.Timer

AfterFunc schedules f to execute after the specified duration. Unlike time.AfterFunc which executes in a separate goroutine, this method executes f synchronously in the goroutine that scheduled the timer, protected by sync.Mutex. This ensures sequential execution of all scheduled functions without race conditions. Returns a Timer that can be used to cancel the scheduled execution.

func (*Dispatcher) Err

func (d *Dispatcher) Err() <-chan error

Err returns a channel that receives an error when the dispatcher stops due to an unrecoverable error.