Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LockedReader ¶
type LockedReader struct {
// contains filtered or unexported fields
}
LockedReader wraps an io.Reader to be safe for concurrent reads.
This type implements io.Reader, returning the same output.
This means acquiring a lock whenever a read happens, so be aware of that for performance or concurrency reasons.
func NewLockedReader ¶
func NewLockedReader(r io.Reader) *LockedReader
NewLockedReader creates a LockedReader by wrapping an underlying value.
func (*LockedReader) Read ¶
func (r *LockedReader) Read(p []byte) (int, error)
Read implements io.Reader for LockedReader
The behavior is to return the same output as the underlying reader. The difference is that it's safe to call this function concurrently.
Naturally, when calling this function concurrently, what value ends up getting read is raced, but you won't end up reading the same value twice, or otherwise messing up the state of the reader.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool represents a pool of workers, used for parallelizing functions.
Functions needing a *Pool will work with a nil receiver, doing the equivalent work on the current thread instead.
By creating a pool, you avoid the overhead of spinning up goroutines for each new operation.
A Pool is only ever intended to be used from a single goroutine, and might cause deadlocks if used by multiple goroutines concurrently.
func NewPool ¶
NewPool creates a new pool, with a certain number of workers.
If count ⩽ 0, this will use the number of available CPUs instead.
func (*Pool) Parallelize ¶
Parallelize calls a function count times, passing in indices from 0..count-1.
The result will be a slice containing [f(0), f(1), ..., f(count - 1)].