pool

package
v0.0.62 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Walk

type Walk struct {
	Burst int // Burst will be set to 1 if less than 1
	// contains filtered or unexported fields
}
Example
package main

import (
	"context"
	"fmt"

	"github.com/searKing/golang/go/x/pool"
)

func main() {

	// chan WalkInfo
	walkChan := make(chan interface{}, 0)

	p := pool.Walk{
		Burst: 1,
	}
	defer p.Wait()

	p.Walk(context.Background(), walkChan, func(name interface{}) error {
		fmt.Printf("%s\n", name)
		return nil
	})

	for i := 0; i < 5; i++ {
		walkChan <- fmt.Sprintf("%d", i)
	}
	close(walkChan)
}
Output:

0
1
2
3
4

func (*Walk) Error

func (p *Walk) Error() error

func (*Walk) TrySetError

func (p *Walk) TrySetError(err error)

func (*Walk) Wait

func (p *Walk) Wait()

Wait blocks until the WaitGroup counter is zero.

func (*Walk) Walk

func (p *Walk) Walk(ctx context.Context, taskChan <-chan interface{}, procFn WalkFunc)

Walk will consume all tasks parallel and block until ctx.Done() or taskChan is closed.

type WalkFunc

type WalkFunc func(task interface{}) error

WalkFunc is the type of the function called for each task processed by Walk. The path argument contains the argument to Walk as a task.

In the case of an error, the info argument will be nil. If an error is returned, processing stops.

Jump to

Keyboard shortcuts

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