Cysharp / R3

The new future of dotnet/reactive and UniRx.
MIT License
2.27k stars 99 forks source link

TakeLast() cause runtime exception #242

Closed luxl closed 3 months ago

luxl commented 3 months ago
var status = Observable.Interval(TimeSpan.FromMilliseconds(100)).Index();
var doSomething = Observable.Interval(TimeSpan.FromMilliseconds(100)).Take(5);
status.TakeUntil(doSomething.TakeLast(1)).Subscribe(Console.WriteLine);

await Task.Delay(TimeSpan.FromDays(1));

the above code will print the following exception:

R3 UnhandleException: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.Collections.Generic.Queue`1.Enumerator.MoveNext()
   at R3.TakeLast`1._TakeLast.OnCompletedCore(Result result)
   at R3.Observer`1.OnCompleted(Result result)

Also, keep run the programme several times, it probably print '0 1 2 3 4', but sometimes print '0 1 2 3', is this expected?

neuecc commented 3 months ago

Thank you, I've checked the problem and fixed it.

keep run the programme several times, it probably print '0 1 2 3 4', but sometimes print '0 1 2 3', is this expected?

Since the count is taken at the same time interval, it may vary slightly due to the ThreadPool.

neuecc commented 3 months ago

released on v1.2.5