jobrun

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2020 License: MIT Imports: 4 Imported by: 0

README

koron-go/jobrun

GoDoc Actions/Go Go Report Card

Package jobrun provides utilities to execute multiple jobs in serial or parallel based on context.Context.

jobrun は複数のジョブを context.Context ベースで直列や並列に実行するのを簡単にするパッケージです。

Getting started

Install or update:

$ go get -u github.com/koron-go/jobrun

Examples

Run jobs in sequentially (serial). This runs job1 then job2.

job1 := jobrun.RunFunc(func(ctx context.Context) error {
    // TODO: do something
    return nil
})
job2 := jobrun.RunFunc(func(ctx context.Context) error {
    // TODO: do something
    return nil
})

err := jobrun.Serial{job1, job2}.Run(context.Background())

// ...(snip)...

If you want to run both jobs in simultaneously (parallel):

err := jobrun.Parallel{job1, job2}.Run(context.Background())

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Parallel

type Parallel []Runner

Parallel defines parallel job runner.

func (*Parallel) Add

func (p *Parallel) Add(r ...Runner) *Parallel

Add adds a runner to Parallel.

func (Parallel) Run

func (p Parallel) Run(ctx context.Context) error

Run implements Runner.

type RunFunc

type RunFunc func(ctx context.Context) error

RunFunc is Runner wrapper for function.

func (RunFunc) Run

func (f RunFunc) Run(ctx context.Context) error

Run implements Runner interface.

type Runner

type Runner interface {
	Run(ctx context.Context) error
}

Runner provides job logic to run.

type Serial

type Serial []Runner

Serial defines serial job runner.

func (*Serial) Add

func (s *Serial) Add(r ...Runner) *Serial

Add adds a runner to Serial.

func (Serial) Run

func (s Serial) Run(ctx context.Context) error

Run implements Runner.

Jump to

Keyboard shortcuts

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