Documentation
¶
Overview ¶
Package channel 提供一些方便的 chan 操作封装
Index ¶
- func ReadManyInTime[T any](ch <-chan T, limit int, withIn time.Duration) (res []T, emptyAndTimeout, emptyAndClosed bool)
- func ReadNonBlocked[T any](ch <-chan T) (v T, empty, emptyAndClosed bool)
- func ReadWithTimeout[T any](ch <-chan T, timeout time.Duration) (v T, emptyAndTimeout, emptyAndClosed bool)
- func WriteNonBlocked[T any](ch chan<- T, v T) (full, closed bool)
- func WriteWithTimeout[T any](ch chan<- T, v T, timeout time.Duration) (full, closed bool)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadManyInTime ¶
func ReadManyInTime[T any]( ch <-chan T, limit int, withIn time.Duration, ) (res []T, emptyAndTimeout, emptyAndClosed bool)
ReadManyInTime 从一个 chan 中尽可能读出数据, 当读取数据超时,或者达到 limit 值时返回。 参数 limit <= 0 时表示无限制。参数 withIn <= 0 则表示将当前 channel 中已有的数据尽数读出 (limit 参数逻辑仍在), 不考虑超时。
func ReadNonBlocked ¶
ReadNonBlocked 非阻塞地从一个 chan 中读出数据。当读取失败时返回
func ReadWithTimeout ¶
func ReadWithTimeout[T any](ch <-chan T, timeout time.Duration) (v T, emptyAndTimeout, emptyAndClosed bool)
ReadWithTimeout 从一个 chan 中读出数据。当读取超时时返回
func WriteNonBlocked ¶
WriteNonBlocked 非阻塞地向一个 chan 中写入数据, 当写入失败时返回
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.