Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadAllResults ¶
func ReadAllResults[T any](iter ResultIter[T]) ([]T, error)
Types ¶
type Iter ¶
type Iter[T any] interface { // Next sets the iterator to the next value, returning true if an attempt was made to get the next value. Next() bool Val() T // Close closes the iterator and any underlying resources. Failure to close an iterator may result in resource leakage (goroutines, FDs, conns, etc.). Close() error }
Iter is an iterator of arbitrary values. Iterators are generally not goroutine-safe, to make them safe just read from them into a channel. For our use cases, these usually have a single reader. This motivates iterators instead of channels, since the overhead of goroutines+channels has a significant performance cost. Using an iterator, you can read results directly without necessarily involving the Go scheduler.
There are a lot of options for an iterator interface, this one was picked for ease-of-use and for highest probability of consumers using it correctly. E.g. because there is a separate method for the value, it's easier to use in a loop but harder to implement.
Hopefully in the future, Go will include an iterator in the language and we can remove this.
type JSONIter ¶
type JSONIter[T any] struct { Decoder *json.Decoder Reader io.Reader // contains filtered or unexported fields }
JSONIter iterates over whitespace-delimited JSON values of a byte stream. This closes the reader if it is a closer, to faciliate easy reading of HTTP responses.
func FromReaderJSON ¶
FromReaderJSON returns an iterator over the given reader that reads whitespace-delimited JSON values.