Created
January 18, 2015 15:03
-
-
Save acple/0545de089fdae023de18 to your computer and use it in GitHub Desktop.
This file contains 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
using System; | |
using System.Reactive.Linq; | |
using System.Reactive.Subjects; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var subject = new Subject<int>(); | |
Observable.Return(0) | |
.SelectMany(_ => subject.AsObservable().FirstAsync()) | |
.Do(_ => subject.OnNext(0)) | |
.Subscribe(x => Console.WriteLine("result:" + x)); | |
subject.OnNext(999); // StackOverflowException!!! | |
} | |
static void Test1() | |
{ | |
var subject = new Subject<int>(); | |
Observable.Return(0) | |
//.SelectMany(_ => subject.AsObservable().FirstAsync()) | |
.SelectMany(async _ => await subject.AsObservable().FirstAsync()) // async/await | |
.Do(_ => subject.OnNext(0)) | |
.Subscribe(x => Console.WriteLine("result:" + x)); | |
subject.OnNext(999); // これはいける result:999 | |
} | |
static void Test2() | |
{ | |
var subject = new Subject<int>(); | |
Observable.Return(0) | |
//.SelectMany(_ => subject.AsObservable().FirstAsync()) | |
.SelectMany(_ => subject.AsObservable().Take(1)) // Take First | |
.Do(_ => subject.OnNext(0)) | |
.Subscribe(x => Console.WriteLine("result:" + x)); | |
subject.OnNext(999); // これもいける result:999 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment