Home > Software design >  What are Publish and SelectMany doing in this query?
What are Publish and SelectMany doing in this query?

Time:02-26

I’ve got new question about one (or two) Reactive methods. In my scenario I needed an observable sequence capable of suppressing other emitted Tasks while the first Task wasn’t completed, and ended up with something like this:

Observable.Interval(TimeSpan.FromMilliseconds(200))
.Select(x => Observable.FromAsync(async () =>
{
    await Task.Delay(1000);
    // Simulating long running task
    Console.WriteLine(x);
}))
.Publish(x => x.FirstAsync().SelectMany(c => c).Repeat())
.Subscribe();

I tried to Google but I really can’t explain few things:

  1. First of all, how that works
  • Related