Skip to content

Commit

Permalink
ReplaySubject race condition #228
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Jun 25, 2024
1 parent d0ee86f commit e016556
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions src/R3/ReplaySubject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public void OnNext(T value)
{
Trim();
replayBuffer.AddLast((timeProvider?.GetTimestamp() ?? 0, value));
}

foreach (var subscription in list.AsSpan())
{
subscription?.observer.OnNext(value);
foreach (var subscription in list.AsSpan())
{
subscription?.observer.OnNext(value);
}
}
}

Expand Down Expand Up @@ -103,27 +103,27 @@ protected override IDisposable SubscribeCore(Observer<T> observer)
{
observer.OnNext(item.value);
}
}

var result = completeState.TryGetResult();
if (result != null)
{
observer.OnCompleted(result.Value);
return Disposable.Empty;
}
var result = completeState.TryGetResult();
if (result != null)
{
observer.OnCompleted(result.Value);
return Disposable.Empty;
}

var subscription = new Subscription(this, observer); // create subscription and add observer to list.
var subscription = new Subscription(this, observer); // create subscription and add observer to list.

// need to check called completed during adding
result = completeState.TryGetResult();
if (result != null)
{
subscription.observer.OnCompleted(result.Value);
subscription.Dispose();
return Disposable.Empty;
}
// need to check called completed during adding
result = completeState.TryGetResult();
if (result != null)
{
subscription.observer.OnCompleted(result.Value);
subscription.Dispose();
return Disposable.Empty;
}

return subscription;
return subscription;
}
}

public void Dispose()
Expand Down

0 comments on commit e016556

Please sign in to comment.