forked from idg10/prog-cs-8-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFilePusher.cs
33 lines (30 loc) · 815 Bytes
/
FilePusher.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.IO;
namespace FundamentalInterfaces
{
public class FilePusher : IObservable<string>
{
private readonly string _path;
public FilePusher(string path)
{
_path = path;
}
public IDisposable Subscribe(IObserver<string> observer)
{
using (var sr = new StreamReader(_path))
{
while (!sr.EndOfStream)
{
observer.OnNext(sr.ReadLine());
}
}
observer.OnCompleted();
return NullDisposable.Instance;
}
private class NullDisposable : IDisposable
{
public static NullDisposable Instance = new NullDisposable();
public void Dispose() { }
}
}
}