README
¶
batch
Run a sequence of data by batch, with optional concurrency, and optional progress printing.
Example
func ExampleBatches_example() {
err := batches.Batches{
From: 1,
To: 307,
BatchSize: 100,
Concurrency: 1,
Work: func(from, to int64) error {
fmt.Printf("\t*do work for [%3d ~ %3d]*\t", from, to)
return nil
},
Output: os.Stdout,
}.Run()
if err != nil {
fmt.Println(err)
}
// Output:
// 17:49:07 [1 ~ 307] total 4 batches
// 17:49:07 [ 1 ~ 100] ... *do work for [ 1 ~ 100]* finished in 31.6µs
// 17:49:07 [101 ~ 200] ... *do work for [101 ~ 200]* finished in 8.9µs
// 17:49:07 [201 ~ 300] ... *do work for [201 ~ 300]* finished in 7.5µs
// 17:49:07 [301 ~ 307] ... *do work for [301 ~ 307]* finished in 7.3µs
// 17:49:07 [1 ~ 307] total 4 batches, finished in 518.5µs
}
Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ElapsedTime ¶
Types ¶
type Batches ¶
type Batches struct { From int64 To int64 BatchSize uint32 // BatchSize defaults to 1 if is 0. Concurrency uint16 Work func(int64, int64) error Output io.Writer }
func (Batches) Run ¶
Example ¶
Output: 1 100 101 200 201 300 301 307
Example (Concurrently) ¶
Output: [[307 208] [207 108] [107 8] [7 7]]
Example (ConcurrentlyWithError) ¶
Output: error
Example (ConcurrentlyWithError2) ¶
Output: error
Example (Desc) ¶
Output: 307 208 207 108 107 8 7 7
Example (OneNumber) ¶
Output: 3 3
Example (OneNumber2) ¶
Output: 3 3
Example (SingleBatch) ¶
Output: 3 1
Example (SingleStep) ¶
Output: 3 3 2 2 1 1
Example (WithError) ¶
Output: 1 100 101 200 201 300 error
Click to show internal directories.
Click to hide internal directories.