Created
December 9, 2014 10:07
-
-
Save neuecc/a5a94ae640fd5871860c to your computer and use it in GitHub Desktop.
AsynchronousLINQ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static IObservable<string> ReadLineAsObservable(string fileName) | |
{ | |
return Observable.Create<string>(async observer => | |
{ | |
try | |
{ | |
using (var sr = new StreamReader(fileName)) | |
{ | |
string s; | |
while ((s = await sr.ReadLineAsync().ConfigureAwait(false)) != null) | |
{ | |
observer.OnNext(s); | |
} | |
} | |
observer.OnCompleted(); | |
} | |
catch (Exception ex) | |
{ | |
observer.OnError(ex); | |
} | |
}); | |
} | |
static void Main(string[] args) | |
{ | |
ReadLineAsObservable("hogehoge.csv") | |
.Select(x => x.Replace("a", "b")) | |
.Subscribe(x => Console.WriteLine(x)); // なんかStringWriterに書く:) | |
Console.ReadLine(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment