gio

package module
v0.0.0-...-ea95d08 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2019 License: MIT Imports: 3 Imported by: 0

README

Build Status codecov

gio

goroutine multiplex .

Usage


func main(){
    result := make(Result, 5)
    m := gio.NewMaster(5, result)
    m.Run()
    defer m.Stop()
    var jobs = newJobs(100)
    m.Push(jobs...)
    runtime.Gosched()
    log.Println("result = ", result)
}


func newJobs(length int) (jobs []gio.Jober) {
    for i := 0; i < length; i++ {
        jobs = append(jobs, job{i})
    }
    return
}

// Next implement by yourself.

// Job is custom job.
type job struct {
    A int
}

// implement the gio.Jober interface
func (j job) Run(result gio.Saver) error {
    // ...

    // save the result
    return result.Save(fmt.Sprintf("job%d", j.A), j.A)
}

var rwmux sync.RWMutex

// Result is custom result
type Result map[string]interface{}

// implement the gio.Saver interface.(you can handle it with sync or async)
func (r Result) Save(v ...interface{}) error {
    rwmux.Lock()
    r[v[0].(string)] = v[1]
    rwmux.Unlock()
    return nil
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Jober

type Jober interface {
	Run(Saver) error
}

Jober interface

type Master

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

Master .

func NewMaster

func NewMaster(maxWork int, result Saver) *Master

NewMaster return a new master.

func (*Master) GetErrs

func (m *Master) GetErrs() []error

GetErrs return all errs.

func (*Master) Push

func (m *Master) Push(jobs ...Jober)

Push jobs into jobqueue.

func (*Master) Run

func (m *Master) Run()

Run start all work.

func (*Master) Stop

func (m *Master) Stop()

Stop . stop all the work.

type Saver

type Saver interface {
	Save(...interface{}) error
}

Saver interface

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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