Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.