channel

package module
v0.0.0-...-655d831 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2025 License: MIT Imports: 1 Imported by: 3

Documentation

Overview

Package channel 提供一些方便的 chan 操作封装

Index

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

func ReadNonBlocked[T any](ch <-chan T) (v T, empty, emptyAndClosed bool)

ReadNonBlocked 非阻塞地从一个 chan 中读出数据。当读取失败时返回

func ReadWithTimeout

func ReadWithTimeout[T any](ch <-chan T, timeout time.Duration) (v T, emptyAndTimeout, emptyAndClosed bool)

ReadWithTimeout 从一个 chan 中读出数据。当读取超时时返回

func WriteNonBlocked

func WriteNonBlocked[T any](ch chan<- T, v T) (full, closed bool)

WriteNonBlocked 非阻塞地向一个 chan 中写入数据, 当写入失败时返回

func WriteWithTimeout

func WriteWithTimeout[T any](ch chan<- T, v T, timeout time.Duration) (full, closed bool)

WriteWithTimeout 带超时向一个 chan 中写入数据, 当时间到了的时候依然写入失败, 说明 channel 是满的, 直接返回

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL