jobrun

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 6, 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

Overview

Package jobrun provides jobs execution utility like in parallel or serial.

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 deprecated

type RunFunc = RunnerFunc

RunFunc is an alias for RunnerFunc, for compatibility.

Deprecated: use RunnerFunc instead.

type Runner

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

Runner provides job logic to run.

type RunnerFunc added in v1.0.1

type RunnerFunc func(ctx context.Context) error

RunnerFunc is Runner wrapper for functions.

func (RunnerFunc) Run added in v1.0.1

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

Run implements Runner interface.

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