queue

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: MIT Imports: 1 Imported by: 1

README

Goroutine concurrency queue process

Build Status codecov

Example

  import "github.com/muhfajar/queue"
  ...
  ALLOC := 6
  q := NewQueue(&Worker{
  	Thread: 3,
  	Alloc:  ALLOC,
  	Set: Callback{
  		TaskDone: func(result interface{}) {
  			rs := result.(string)
  			fmt.Println(rs)
  		},
  		QueueDone: func() {
  			fmt.Println("done")
  		},
  	},
  })

  strings := []string{"hello", "world", "fajar", "muhfajar", "queue", "github"}
  for i, s := range strings {
  	index, value := i, s
  	task := func() interface{} {
  		time.Sleep(time.Duration(1) * time.Second)
  		return fmt.Sprintf("pid: %d :: %s", index, value)
  	} 

  	q.Append(task)
  }
 
  q.Start()

Documentation

Index

Constants

View Source
const (
	DefaultMaxThread = 25
	DefaultMaxAlloc  = 1000
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback

type Callback struct {
	TaskDone  func(...interface{})
	QueueDone func()
}

type Worker

type Worker struct {
	Thread int
	Alloc  int
	Set    Callback
	// contains filtered or unexported fields
}

func NewQueue

func NewQueue(w *Worker) *Worker

func (*Worker) Append

func (w *Worker) Append(task func() interface{})

func (*Worker) Start

func (w *Worker) Start()

Jump to

Keyboard shortcuts

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