This repository was archived by the owner on Feb 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 887
This repository was archived by the owner on Feb 16, 2024. It is now read-only.
Issue with ReplaySubject and Take #292
Copy link
Copy link
Open
Description
I have a situation where I'm using a ReplaySubject and Take(int). Here's a minimal example of how to reproduce the problem:
ReplaySubject<string[]> rep = new ReplaySubject<string[]>(1);
rep.OnNext(new[] { "start" });
rep
.Take(1)
.Subscribe(strings => {
var list = strings.ToList();
list.Add("added");
rep.OnNext(list.ToArray());
});
And here are the relevant parts of the exception that is thrown:
InvalidOperationException: Collection was modified after the enumerator was instantiated.
System.ThrowHelper.ThrowInvalidOperationException (System.ExceptionResource resource) (at <3649452ae23840d49bd323a708498f78>:0)
System.Collections.Generic.Queue`1+Enumerator[T].MoveNext () (at <3649452ae23840d49bd323a708498f78>:0)
UniRx.ReplaySubject`1[T].Subscribe (System.IObserver`1[T] observer) (at Assets/Plugins/UniRx/Scripts/Subjects/ReplaySubject.cs:170)
UniRx.Operators.TakeObservable`1[T].SubscribeCore (System.IObserver`1[T] observer, System.IDisposable cancel) (at Assets/Plugins/UniRx/Scripts/Operators/Take.cs:58)
UniRx.Operators.OperatorObservableBase`1[T].Subscribe (System.IObserver`1[T] observer) (at Assets/Plugins/UniRx/Scripts/Operators/OperatorObservableBase.cs:34)
UniRx.ObservableExtensions.Subscribe[T] (System.IObservable`1[T] source, System.Action`1[T] onNext) (at Assets/Plugins/UniRx/Scripts/Observer.cs:413)
If I remove the .Take(1) (and the inner OnNext to avoid an infinite loop), everything works as expected.
Luckily, since I'm basically using a ReplaySubject to act like a BehaviorSubject, I can just change to using one of those (no problem there, it seems), but this was still annoying.
System Info:
iMac (27-inch, Late 2013)
macOS 10.12.6
Unity version 2017.3.1f1 personal
Scripting Runtime version .NET 4.6 equivalent
API Level .NET 4.6
Metadata
Metadata
Assignees
Labels
No labels