Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WaitForAllReady ¶
WaitForAllReady returns true if all objects are ready, or false if one of them is closed or the context ended before that.
Types ¶
type Reader ¶
type Reader[T any] interface { WithContext[T] Read() (T, bool) ReadWithTimeout(time.Duration) (T, bool) }
Reader helps in reading from channels with context.
type ReaderWriter ¶
type ReaderWriter[T any] interface { Reader[T] Writer[T] }
ReaderWriter helps in reading and writing to channels with context. It enforces a quick release pattern so a worker will stop immediately when the context is done, and won't be hanged until the channel is closed (if ever). By using the helper instead of using channels directly, we can make sure our system never hangs on channels. This is helpful for two scenarios when close(chan) can't be used:
- We want to stop the worker even if there are still items in the channel.
- There are multiple writers to a channel, so it is difficult to close the channel while avoiding possible panics.
func Make ¶
func Make[T any](ctx context.Context, size int) ReaderWriter[T]
Make create a new channel with context.
func NewReaderWriter ¶
func NewReaderWriter[T any](ctx context.Context, inputOutput chan T) ReaderWriter[T]
NewReaderWriter instantiate a ReaderWriter.
type Ready ¶
type Ready struct {
// contains filtered or unexported fields
}
Ready supports waiting for readiness and notifying of readiness. It also supports closing to release waiters.
func (*Ready) WaitForReady ¶
WaitForReady returns true if the object is ready, or false if it is closed or the context ended before that.
type WithContext ¶
type WithContext[T any] interface { Context() context.Context WithContext(ctx context.Context) ReaderWriter[T] }
WithContext supports fetching and updating the context.