Skip to content

Instantly share code, notes, and snippets.

@neuecc
Created December 9, 2014 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neuecc/a5a94ae640fd5871860c to your computer and use it in GitHub Desktop.
Save neuecc/a5a94ae640fd5871860c to your computer and use it in GitHub Desktop.
AsynchronousLINQ
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