sync

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Condition

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

Condition could be used to wait for a synced change of something.

func (*Condition) Broadcast

func (instance *Condition) Broadcast() error

Broadcast broadcast trigger to the condition. If there are more then one listener, every of them will receive the trigger. This method is not blocking.

func (*Condition) Interrupt

func (instance *Condition) Interrupt()

Interrupt interrupts every possible current running Wait() method of this instance. In this instance, nobody will be able to call Wait() from this moment on.

func (*Condition) Mutex

func (instance *Condition) Mutex() *Mutex

Mutex returns the instance of this Condition.

func (*Condition) Send

func (instance *Condition) Send() error

Send sends ONE trigger to the condition. If there are more than one listener, only one of them will receive the trigger. This method is not a blocking method.

func (*Condition) Wait

func (instance *Condition) Wait(duration time.Duration) error

Wait waits for someone that calls Send() or Broadcast() on this Condition instance for the given maximum duration. If someone calls Interrupt() or there is no trigger received within the maximum duration an error will be returned.

type Group added in v0.1.6

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

Group is a couple of tools (like sleep, locks, conditions, ...) that are grouped together and could be interrupted by calling Interrupt() method.

func NewGroup added in v0.1.6

func NewGroup() *Group

NewGroup creates a new SyncGroup instance.

func (*Group) Interrupt added in v0.1.6

func (instance *Group) Interrupt()

Interrupt interrupts every action on this SyncGroup. After calling this method the instance is no longer usable anymore.

func (*Group) NewCondition added in v0.1.6

func (instance *Group) NewCondition(mutex *Mutex) *Condition

NewCondition creates a new condition in the current SyncGroup with the given Mutex.

func (*Group) NewGroup added in v0.1.6

func (instance *Group) NewGroup() *Group

NewGroup creates a new sub instance of this instance.

func (*Group) NewMutex added in v0.1.6

func (instance *Group) NewMutex() *Mutex

NewMutex creates a new instance of Mutex in the current SyncGroup.

func (*Group) Sleep added in v0.1.6

func (instance *Group) Sleep(duration time.Duration) error

Sleep sleeps for the given duration but is interruptable by calling Interrupt() at the current SyncGroup.

type Interruptable

type Interruptable interface {
	Interrupt()
}

Interruptable represents an object that could be interrupted.

type InterruptedError

type InterruptedError struct{}

InterruptedError occurs if someone has called the Interrupt() method.

func (InterruptedError) Error

func (instance InterruptedError) Error() string

type Mutex

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

Mutex is a lock in a SyncGroup.

func (*Mutex) Interrupt

func (instance *Mutex) Interrupt()

Interrupt interrupts every possible current running Lock() and TryLock() method of this instance. In this instance, nobody will be able to call Lock() and TryLock() from this moment on.

func (*Mutex) Lock

func (instance *Mutex) Lock() error

Lock locks the current thread to this mutex. If this is not possible an error will be returned. This method is blocking until locking is possible.

func (*Mutex) TryLock

func (instance *Mutex) TryLock(timeout time.Duration) bool

TryLock tries to locks the current thread to this mutex. This method will wait for a maximum of the given duration to get the lock - in this case "true" is returned.

func (*Mutex) Unlock

func (instance *Mutex) Unlock()

Unlock unlocks the current thread from this Mutex.

type TimeoutError

type TimeoutError struct{}

TimeoutError occurs if a timeout condition is reached.

func (TimeoutError) Error

func (instance TimeoutError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL