executor

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package executor provides an implementation of the Executor to perform background processing, limiting resource consumption when executing a collection of jobs.

Executor example:

exe := executor.New(10)
defer exe.Shutdown()

for i := 0; i < 100; i++ {
	idx := i
	err := exe.Schedule(func(ctx context.Context) {
		select {
		case <-ctx.Done():
			log.Printf("[JOB] ID %d - stop \n", idx)
			return
		default:
			log.Printf("[JOB] ID %d \n", idx)
			time.Sleep(time.Millisecond * 100)
	})
	if err != nil {
		t.Log(err)
		break
	}
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Executor

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

Executor contains logic for goroutine execution.

func New

func New(size int) *Executor

New returns an initialized goroutine executor.

The size parameter determines the limit of the executor.

func (*Executor) IsTerminated

func (e *Executor) IsTerminated() bool

IsTerminated return if the executor is terminated.

func (*Executor) Schedule

func (e *Executor) Schedule(job func(ctx context.Context)) error

Schedule schedules the work to be performed on the executors.

func (*Executor) Shutdown

func (e *Executor) Shutdown()

Shutdown closes the executor.

Jump to

Keyboard shortcuts

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