1

I started using the ExhaustMap, all well and very valueable extension, until I tried to Retry.

Take the next snippet which is a modified version of the original post usage sample.

await Observable
    .Interval(TimeSpan.FromMilliseconds(200))
    .Select(x => (int)x + 1)
    .Take(10)
    .Do(x => Console.WriteLine($"Input: {x}"))
    .ExhaustMap(x => Observable.Throw<Unit>(new InvalidOperationException()))
    .Retry(2)
    .Do(x => Console.WriteLine($"Result: {x}")).FirstOrDefaultAsync();

Exit code is -532462766 (Unhandled exception. System.ObjectDisposedException: The semaphore has been disposed.

How to appropriately handle this case, semaphore does not have a public IsDisposed property and I am expecting an InValidOperationException and not an ObjectDisposed

stuartd
  • 70,509
  • 14
  • 132
  • 163
Apostolis Bekiaris
  • 2,145
  • 2
  • 18
  • 21
  • 1
    Yeah, I recently discovered that the Rx operators `Using` and `Finally` can be problematic ([1](https://github.com/dotnet/reactive/issues/1632), [2](https://stackoverflow.com/questions/69815945/how-to-implement-a-better-finally-rx-operator)), and [my implementation](https://stackoverflow.com/a/64356119/11178549) uses both of them. I just patched it by replacing the `Using` with the `Defer`, which means that the `SemaphoreSlim` will not be disposed. This is probably [not a big deal](https://stackoverflow.com/questions/32033416). I'll see if I can come up with a better implementation. – Theodor Zoulias Feb 08 '22 at 14:02
  • 1
    I just replaced the `SemaphoreSlim`-based implementation with a more lightweight `Interlocked`-based implementation. Using a `SemaphoreSlim` is probably overkill for this purpose, because its signaling functionality is not used. All that is really needed is a `bool` flag, that indicates whether a subsequence is currently subscribed or not. – Theodor Zoulias Feb 08 '22 at 15:16

0 Answers0