scheduler

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2023 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Dispatcher

type Dispatcher struct {
	TaskChannel     chan Job      // Store all job
	DispatchControl chan bool     // Control add job go routine
	WorkerPool      chan chan Job // Store worker private job channel
	WorkerList      []*Worker     // Store worker instance
	MaxWorker       int           // Max worker number
	IsClosed        bool          // Dispatcher is closed ?
}

Dispatcher is used to dispatch job

func NewDispatcher

func NewDispatcher(maxWorker int) *Dispatcher

NewDispatcher is used to create dispatch

func (*Dispatcher) AddJob

func (d *Dispatcher) AddJob(job Job) bool

AddJob is used job to global job channel

func (*Dispatcher) Close

func (d *Dispatcher) Close()

Close dispatch

func (*Dispatcher) Run

func (d *Dispatcher) Run()

Run dispatcher

type Job

type Job func()

Job scheduler must implement method

type Worker

type Worker struct {
	Dispatcher *Dispatcher
	JobChannel chan Job
	Quit       chan bool
	ID         int
}

Worker struct

func NewWorker

func NewWorker(d *Dispatcher, ID int) *Worker

NewWorker is used to create a new worker

func (*Worker) Start

func (w *Worker) Start()

Start worker

func (*Worker) Stop

func (w *Worker) Stop()

Stop worker

Jump to

Keyboard shortcuts

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