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版)
互操作
101
该异常传递到可观察流时,会被包装到
AggregateException
中。这与彼此关联的块传播错
误的方式类似。
使用数据流网格并把它当作可观察流的终点,这个过程会稍微复杂一点。下面的示例代码
调用了
AsObserver
,让数据流块能够订阅可观察流:
IObservable<DateTimeOffset> ticks =
Observable.Interval(TimeSpan.FromSeconds(1))
.Timestamp()
.Select(x => x.Timestamp)
.Take(5);
var
display =
new
ActionBlock<DateTimeOffset>(x => Trace.WriteLine(x));
ticks.Subscribe(display.AsObserver());
try
{
display.Completion.Wait();
Trace.WriteLine(
"
Done.");
}
catch
(Exception ex)
{
Trace.WriteLine(ex);
}
就像之前一样,可观察流的完成会转化成数据流块的完成,任何可观察流的错误都会转化
成数据流块的错误。
讨论
从概念角度来看,数据流块和可观察流存在诸多共通之处。它们都可以传递数据,都能理
解完成和错误。但是,它们是为不同场景设计的,
TPL
数据流适用于异步编程和并行编程
同时存在的情况,而
System.Reactive
适用于响应式编程。然而,这种概念上的交集让它们 ...
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