poolasync

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2020 License: MIT Imports: 4 Imported by: 0

README

pool-async

pool-async is a tool for goroutines with a pool.

#Quick start

package main

import "github.com/joy717/poolasync"

func main() {
  pa := poolasync.NewDefaultPoolAsync()
  pa.DoWitError(func() error {
    fmt.Println("goroutine 1")
    return nil
  }).DoWitError(func() error {
    fmt.Println("goroutine 2")
    return fmt.Errorf("goroutine 2 err")
  })
  
  if err := pa.Wait(); err != nil {
    t.Println("the 1st non-nil err: ", err)
  }
}

If you like this tool, star it to make this tool to be known by more people.

Documentation

Index

Constants

View Source
const DefaultLimit = 10

Variables

This section is empty.

Functions

This section is empty.

Types

type PoolAsync

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

PoolAsync has a pool for async.

func NewDefaultPoolAsync

func NewDefaultPoolAsync() *PoolAsync

func NewPoolAsync

func NewPoolAsync(count int) *PoolAsync

func (*PoolAsync) Do

func (a *PoolAsync) Do(f func()) *PoolAsync

Deprecated

get a ticket from poolChan. if got, then do f(), if not, wait for poolChan.

func (*PoolAsync) DoWitError

func (a *PoolAsync) DoWitError(f func() error) *PoolAsync

get a ticket from poolChan. if got, then do f(), if not, wait for poolChan.

func (*PoolAsync) GetCurrentJobSize

func (a *PoolAsync) GetCurrentJobSize() int32

func (*PoolAsync) GetErrors

func (a *PoolAsync) GetErrors() []error

func (*PoolAsync) Wait

func (a *PoolAsync) Wait() error

wait will block until all jobs done. and return the first none-nil error.

IMPORTANT: Wait must be called after ALL Do/DoWitError

Jump to

Keyboard shortcuts

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