Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer .
Example ¶
buf := NewBuffer(&testWriter{2}, 4) n, err := buf.WriteN(1, 2, 3, 4, 5, 6, 7, 8, 9) fmt.Printf("writes: %d, buffered: %v, err: %s\n", n, buf.buf, err) err = buf.Close() fmt.Println(err)
Output: WriteN size: 4, data: [1 2 3 4] writes: 8, buffered: [5 6 7 8], err: buffer max capacity Close buffer max capacity
Example (For) ¶
buf := NewBuffer(&testWriter{100}, 3) data := make([]interface{}, 10, 10) for i := range data { data[i] = i } for i := 0; i < 10; i++ { n, err := buf.WriteN(data[0 : 1+i%10]...) if err != nil { fmt.Println(n, buf.buf, err) break } } err := buf.Close() fmt.Println(buf.buf, err)
Output: WriteN size: 3, data: [0 0 1] WriteN size: 3, data: [0 1 2] WriteN size: 3, data: [0 1 2] WriteN size: 3, data: [3 0 1] WriteN size: 3, data: [2 3 4] WriteN size: 3, data: [0 1 2] WriteN size: 3, data: [3 4 5] WriteN size: 3, data: [0 1 2] WriteN size: 3, data: [3 4 5] WriteN size: 3, data: [6 0 1] WriteN size: 3, data: [2 3 4] WriteN size: 3, data: [5 6 7] WriteN size: 3, data: [0 1 2] WriteN size: 3, data: [3 4 5] WriteN size: 3, data: [6 7 8] WriteN size: 3, data: [0 1 2] WriteN size: 3, data: [3 4 5] WriteN size: 3, data: [6 7 8] WriteN size: 1, data: [9] Close [] <nil>
Example (Write) ¶
buf := NewBuffer(&testWriter{10}, 3) n, err := buf.WriteN(1, 2, 3, 4, 5) fmt.Printf("writes: %d, buffered: %v, err: %v\n", n, buf.buf, err) n, err = buf.WriteN(6) fmt.Printf("writes: %d, buffered: %v, err: %v\n", n, buf.buf, err) n, err = buf.WriteN(7, 8, 9) fmt.Printf("writes: %d, buffered: %v, err: %v\n", n, buf.buf, err) n, err = buf.WriteN(10, 11) fmt.Printf("writes: %d, buffered: %v, err: %v\n", n, buf.buf, err) n, err = buf.WriteN(10, 11) fmt.Printf("writes: %d, buffered: %v, err: %v\n", n, buf.buf, err)
Output: WriteN size: 3, data: [1 2 3] writes: 5, buffered: [4 5], err: <nil> WriteN size: 3, data: [4 5 6] writes: 1, buffered: [], err: <nil> writes: 3, buffered: [7 8 9], err: <nil> WriteN size: 3, data: [7 8 9] writes: 2, buffered: [10 11], err: <nil> WriteN size: 3, data: [10 11 10] writes: 2, buffered: [11], err: <nil>
type Writer ¶
type Writer interface { Write(data interface{}) error WriteN(data ...interface{}) (int, error) Close() error }
Writer .
func ParallelBatch ¶
func ParallelBatch( writers func(i uint64) Writer, parallelism, size uint64, timeout time.Duration, errorh ErrorHandler, ) Writer
ParallelBatch .
Click to show internal directories.
Click to hide internal directories.