async

package
v0.171.33 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTaskOverwritten = errors.New("task overwritten")

Functions

This section is empty.

Types

type AtomicGroup

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

AtomicGroup terminates as soon as first goroutine terminates..

func NewAtomicGroup

func NewAtomicGroup(parent context.Context) *AtomicGroup

func (*AtomicGroup) Add

func (d *AtomicGroup) Add(cmd Command)

Go spawns function in a goroutine and stores results or errors.

func (*AtomicGroup) Error

func (d *AtomicGroup) Error() error

Error stores an error that was reported by any of the downloader. Should be called after Wait.

func (*AtomicGroup) Stop

func (d *AtomicGroup) Stop()

func (*AtomicGroup) Wait

func (d *AtomicGroup) Wait()

Wait for all downloaders to finish.

func (*AtomicGroup) WaitAsync

func (d *AtomicGroup) WaitAsync() <-chan struct{}

type Command

type Command func(context.Context) error

type Commander added in v0.148.4

type Commander interface {
	Command(inteval ...time.Duration) Command
}

type FiniteCommand

type FiniteCommand struct {
	Interval time.Duration
	Runable  func(context.Context) error
}

FiniteCommand terminates when error is nil.

func (FiniteCommand) Run

func (c FiniteCommand) Run(ctx context.Context) error

type Group

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

func NewGroup

func NewGroup(parent context.Context) *Group

func (*Group) Add

func (g *Group) Add(cmd Command)

func (*Group) Stop

func (g *Group) Stop()

func (*Group) Wait

func (g *Group) Wait()

func (*Group) WaitAsync

func (g *Group) WaitAsync() <-chan struct{}

type InfiniteCommand

type InfiniteCommand struct {
	Interval time.Duration
	Runable  func(context.Context) error
}

InfiniteCommand runs until context is closed.

func (InfiniteCommand) Run

func (c InfiniteCommand) Run(ctx context.Context) error

type MultiClientScheduler added in v0.163.14

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

func NewMultiClientScheduler added in v0.163.14

func NewMultiClientScheduler() *MultiClientScheduler

func (*MultiClientScheduler) Enqueue added in v0.163.14

func (s *MultiClientScheduler) Enqueue(requestID int32, taskType TaskType, taskFn taskFunction, resFn resultFunction) (ignored bool)

func (*MultiClientScheduler) Stop added in v0.163.14

func (s *MultiClientScheduler) Stop()

type QueuedAtomicGroup added in v0.148.4

type QueuedAtomicGroup struct {
	*AtomicGroup
	// contains filtered or unexported fields
}

func NewQueuedAtomicGroup added in v0.148.4

func NewQueuedAtomicGroup(parent context.Context, limit uint32) *QueuedAtomicGroup

func (*QueuedAtomicGroup) Add added in v0.148.4

func (d *QueuedAtomicGroup) Add(cmd Command)

type ReplacementPolicy added in v0.162.13

type ReplacementPolicy = int
const (
	ReplacementPolicyCancelOld ReplacementPolicy = iota
	ReplacementPolicyIgnoreNew
)

type Scheduler added in v0.162.13

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

func NewScheduler added in v0.162.13

func NewScheduler() *Scheduler

func (*Scheduler) Enqueue added in v0.162.13

func (s *Scheduler) Enqueue(taskType TaskType, taskFn taskFunction, resFn resultFunction) (ignored bool)

Enqueue provides a queue of task types allowing only one task at a time of the corresponding type. The running task is the first one in the queue (s.queue.Oldest())

Schedule policy for new tasks

  • pushed at the back of the queue (s.queue.PushBack()) if none of the same time already scheduled
  • overwrite the queued one of the same type, depending on the policy
  • In case of ReplacementPolicyIgnoreNew, the new task will be ignored
  • In case of ReplacementPolicyCancelOld, the old running task will be canceled or if not yet run overwritten and the new one will be executed when its turn comes.

The task function (taskFn) might not be executed if

  • the task is ignored
  • the task is overwritten. The result function (resFn) will be called with ErrTaskOverwritten

The result function (resFn) will always be called if the task is not ignored

func (*Scheduler) Stop added in v0.162.13

func (s *Scheduler) Stop()

type SingleShotCommand added in v0.170.0

type SingleShotCommand struct {
	Interval time.Duration
	Init     func(context.Context) error
	Runable  func(context.Context) error
}

SingleShotCommand runs once.

func (SingleShotCommand) Run added in v0.170.0

type TaskType added in v0.162.13

type TaskType struct {
	ID     int64
	Policy ReplacementPolicy
}

Jump to

Keyboard shortcuts

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