Skip to content

Commit

Permalink
4.x: Fix accidental behavior change with Task-based Create methods co…
Browse files Browse the repository at this point in the history
…mpleting when the body ends
  • Loading branch information
akarnokd committed Sep 28, 2018
1 parent 65be066 commit b2a449f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public void Dispose()

public void OnCompleted()
{
_observer.OnCompleted();
}

public void OnError(Exception error)
Expand Down Expand Up @@ -233,7 +232,6 @@ public void Dispose()

public void OnCompleted()
{
_observer.OnCompleted();
}

public void OnError(Exception error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -705,5 +705,46 @@ public void CreateAsync_Action_Token()
Assert.True(lst.Take(10).SequenceEqual(Enumerable.Repeat(42, 10)));
}


[Fact]
public void CreateWithTaskDisposable_NoPrematureTermination()
{
var obs = Observable.Create<int>(async o =>
{
// avoid warning on async o due to no await
await Task.CompletedTask;
var inner = Observable.Range(1, 3);
return inner.Subscribe(x =>
{
o.OnNext(x);
});
});

var result = obs.Take(1).Wait();
}

[Fact]
public void CreateWithTaskAction_NoPrematureTermination()
{
var obs = Observable.Create<int>(async o =>
{
// avoid warning on async o due to no await
await Task.CompletedTask;
var inner = Observable.Range(1, 3);
var d = inner.Subscribe(x =>
{
o.OnNext(x);
});
Action a = () => d.Dispose();
return a;
});

var result = obs.Take(1).Wait();
}
}
}

0 comments on commit b2a449f

Please sign in to comment.