routine

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Map added in v1.0.2

func Map(size, numWorker int, f func(i int) error) error

Map is a helper function to parallel operate on slice. Example usage: ```

itemIDs := []int{1, 2, 3}
items := make([]*Item, len(itemIDs))
routine.Map(len(items), 10, func(i int) {
  items[i] = getItemByID(itemIDs[i])
})

```

func MapWithContext added in v1.0.2

func MapWithContext(ctx context.Context, size, numWorker int, f func(ctx context.Context, i int) error) error

func MapWithCtxTimeout

func MapWithCtxTimeout(baseCtx context.Context, size, numWorker int, timeout time.Duration, f func(ctx context.Context, i int) error) error

func MapWithTimeout added in v1.0.2

func MapWithTimeout(size, numWorker int, timeout time.Duration, f func(ctx context.Context, i int) error) error

MapWithTimeout is the same as Map, except each function need to be executed within timeout. Important reminder to handle the context provided: It is better to check the `ctx.Err() == nil` before any write operation, because the function may be canceled at any momement, and the underlying resource refering may have already been discarded.

Types

This section is empty.

Jump to

Keyboard shortcuts

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