pool

package
v0.0.111 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2021 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() error

Wait blocks until the WaitGroup counter is zero.

func (*Walk) Walk

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

Walk will consume all tasks parallel and block until ctx.Done() or taskChan is closed. Walk returns a channel that's closed when work done on behalf of this walk should be canceled. Done may return nil if this walk can never be canceled. Successive calls to Done return the same value. The close of the Done channel may happen asynchronously, after the cancel function returns.

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