miu

module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2022 License: Apache-2.0

README

miu


Miu is a go work pool implementation, which can help you manage gorontine in the project。

Installation


miu requires a Go version with modules support. So make sure to initialize a Go module:

$ go mod init github.com/my/project

And then install miu:

$ go get github.com/qskyo/miu

Quickstart


package main

import (
    "fmt"
    "time"
    "github.com/google/uuid"
    "github.com/qskyo/miu/core"
)

type TestTask struct {
    core.DefaultTask
}

func (t *TestTask) Run() {
    fmt.Printf("task[id=%s] is running\n", t.GetTaskId())
    time.Sleep(1 * time.Second)
}

func main() {
    workPool := core.NewFixedWorkPool(2, 10)
    workPool.Start()
    go exec(workPool)
    time.Sleep(3 * time.Second)
    workPool.Shutdown()
    time.Sleep(5 * time.Second)
}

func exec(workPool core.WorkPool) {
    for i := 0; i < 30; i++ {
        task := &TestTask{}
        task.Id = uuid.NewString()
        workPool.Execute(task)
    }
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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