Skip to content

Commit 9a6e8b2

Browse files
authored
Merge pull request #816 from akarnokd/FixCreateTaskInvalidCompletion
4.x: Fix accidental behavior change with Task-based Create methods completing when the body ends
2 parents 65be066 + b2a449f commit 9a6e8b2

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

Rx.NET/Source/src/System.Reactive/Linq/QueryLanguage.Creation.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ public void Dispose()
155155

156156
public void OnCompleted()
157157
{
158-
_observer.OnCompleted();
159158
}
160159

161160
public void OnError(Exception error)
@@ -233,7 +232,6 @@ public void Dispose()
233232

234233
public void OnCompleted()
235234
{
236-
_observer.OnCompleted();
237235
}
238236

239237
public void OnError(Exception error)

Rx.NET/Source/tests/Tests.System.Reactive/Tests/Linq/Observable/CreateAsyncTest.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,5 +705,46 @@ public void CreateAsync_Action_Token()
705705
Assert.True(lst.Take(10).SequenceEqual(Enumerable.Repeat(42, 10)));
706706
}
707707

708+
709+
[Fact]
710+
public void CreateWithTaskDisposable_NoPrematureTermination()
711+
{
712+
var obs = Observable.Create<int>(async o =>
713+
{
714+
// avoid warning on async o due to no await
715+
await Task.CompletedTask;
716+
717+
var inner = Observable.Range(1, 3);
718+
719+
return inner.Subscribe(x =>
720+
{
721+
o.OnNext(x);
722+
});
723+
});
724+
725+
var result = obs.Take(1).Wait();
726+
}
727+
728+
[Fact]
729+
public void CreateWithTaskAction_NoPrematureTermination()
730+
{
731+
var obs = Observable.Create<int>(async o =>
732+
{
733+
// avoid warning on async o due to no await
734+
await Task.CompletedTask;
735+
736+
var inner = Observable.Range(1, 3);
737+
738+
var d = inner.Subscribe(x =>
739+
{
740+
o.OnNext(x);
741+
});
742+
743+
Action a = () => d.Dispose();
744+
return a;
745+
});
746+
747+
var result = obs.Take(1).Wait();
748+
}
708749
}
709750
}

0 commit comments

Comments
 (0)