Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable/ToList.cs

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
3 #if !NO_PERF
4 using System;
5 using System.Collections.Generic;
6
7 namespace System.Reactive.Linq.ObservableImpl
8 {
9 class ToList<TSource> : Producer<IList<TSource>>
10 {
11 private readonly IObservable<TSource> _source;
12
13 public ToList(IObservable<TSource> source)
14 {
15 _source = source;
16 }
17
18 protected override IDisposable Run(IObserver<IList<TSource>> observer, IDisposable cancel, Action<IDisposable> setSink)
19 {
20 var sink = new _(observer, cancel);
21 setSink(sink);
22 return _source.SubscribeSafe(sink);
23 }
24
25 class _ : Sink<IList<TSource>>, IObserver<TSource>
26 {
27 private List<TSource> _list;
28
29 public _(IObserver<IList<TSource>> observer, IDisposable cancel)
30 : base(observer, cancel)
31 {
32 _list = new List<TSource>();
33 }
34
35 public void OnNext(TSource value)
36 {
37 _list.Add(value);
38 }
39
40 public void OnError(Exception error)
41 {
42 base._observer.OnError(error);
43 base.Dispose();
44 }
45
46 public void OnCompleted()
47 {
48 base._observer.OnNext(_list);
49 base._observer.OnCompleted();
50 base.Dispose();
51 }
52 }
53 }
54 }
55 #endif