Skip to Content
C#并发编程经典实例(第2版)
book

C#并发编程经典实例(第2版)

by Stephen Cleary
November 2020
Intermediate to advanced
226 pages
5h 34m
Chinese
Posts & Telecom Press
Content preview from C#并发编程经典实例(第2版)
98
8
讨论
System.Reactive
库在
async
出现之前就已经存在了,但有了本节介绍的运算符,它便能与
async
代码良好地互操作。虽然通过其他的
System.Reactive
运算符也能实现同样的功能,
但我还是推荐使用本节介绍的运算符。
参阅
8.5
节探讨通过异步代码来消耗可观察流。
8.8
节探讨将包含异步代码的数据流块用作可观察流的输入。
8.7
 异步流与数据流网格
问题
假设有一部分解决方案使用了异步流,另一部分使用了数据流网格,现在需要在两者之间
传递数据。
解决方案
通道类型拥有将该类型作为异步流消耗的特性,参见
9.8
节。将
TPL
数据流块作为异步流
来消耗,这种做法比较笨拙,但并非不可行。最简单的办法是为数据流块定义扩展方法,
让其
API
更接近通道,然后通过该扩展方法将它们作为异步流来消耗:
public static class
DataflowExtensions
{
public static bool
TryReceiveItem<T>(
this
ISourceBlock<T> block,
out
T
value
)
{
if
(block
is
IReceivableSourceBlock<T> receivableSourceBlock)
return
receivableSourceBlock.TryReceive(
out value
);
try
{
value
= block.Receive(TimeSpan.Zero);
return true ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

解密金融数据

解密金融数据

Justin Pauley
PHP编程:第4版

PHP编程:第4版

Kevin Tatroe, Peter MacIntyre

Publisher Resources

ISBN: 9787115550606