一款简单易用的基础网络通讯组件库。

AsyncExchangeT

精简版线程安全单槽异步交接(单生产者 + 单消费者,不支持并发写队列): 写:一次只能有一个未消费数据,写调用返回的任务在该数据被读取并 Dispose 后完成。 读:无数据则挂起,得到 ReadLease 后需 Dispose 触发写端完成。Complete 后拒绝新写;若无数据则后续 Read 返回完成租约。

Definition

命名空间: TouchSocket.Core
程序集: TouchSocket.Core (在 TouchSocket.Core.dll 中) 版本:4.0.0-beta.143+5fcca7a4e70968794985dc3793adc50531308be6
C#
public sealed class AsyncExchange<T> : IValueTaskSource<ReadLease<T>>, 
	IValueTaskSource
Inheritance
Object    AsyncExchangeT
Implements
IValueTaskSource, IValueTaskSourceReadLeaseT

类型参数

T

[缺少 "T:TouchSocket.Core.AsyncExchange`1" 的 <typeparam name="T"/> 文档]

构造函数

AsyncExchangeT初始化 AsyncExchangeT 类的一个新实例

属性

IsCompleted 获取当前是否已完成(即已调用 Complete,且没有未消费数据和挂起的读写操作)。

方法

Complete 标记当前交接已完成。调用后不再接受新的写入请求, 若当前没有未消费数据且有挂起的读取操作,则立即完成该读取操作。
EqualsDetermines whether the specified object is equal to the current object.
(继承自 Object。)
GetHashCodeServes as the default hash function.
(继承自 Object。)
GetTypeGets the Type of the current instance.
(继承自 Object。)
ReadAsync 异步读取数据。如果当前有可用数据则立即返回,否则挂起等待数据写入或交接完成。 返回的 ReadLeaseT 需在读取后调用 Dispose 以释放资源并通知写端完成。 若已完成交接,则返回已完成的租约。
Reset 重置当前交接状态。仅在已完成且无未消费数据和挂起操作时可调用, 否则会抛出异常。重置后可重新开始新的交接流程。
ToStringReturns a string that represents the current object.
(继承自 Object。)
WriteAsync 异步写入数据。如果当前有未消费数据或有挂起的写操作,则抛出异常; 否则将数据写入并挂起等待读取端消费,消费后写操作完成。 若已完成交接,则抛出异常。

扩展方法

Map 将源对象的属性映射到目标对象的属性中。
(由 Mapper 定义。)
Map 将源对象映射到目标类型的实例。
(由 Mapper 定义。)
MapTTarget 将源对象映射到指定目标类型的新实例。
(由 Mapper 定义。)
ToJsonString 转换为Json
(由 SerializeConvert 定义。)

显式接口实现

IValueTaskSourceGetResultGets the result of the IValueTaskSource.
IValueTaskSourceGetStatusGets the status of the current operation.
IValueTaskSourceOnCompletedSchedules the continuation action for this IValueTaskSource.
IValueTaskSourceReadLeaseTGetResultGets the result of the IValueTaskSourceTResult.
IValueTaskSourceReadLeaseTGetStatusGets the status of the current operation.
IValueTaskSourceReadLeaseTOnCompletedSchedules the continuation action for this IValueTaskSourceTResult.

参见