-
Notifications
You must be signed in to change notification settings - Fork 774
TakeUntil with CancellationToken #2222
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
9c6338c
Implementing TakeUntil with CancellationToken (#2182)
nilsauf b3ae602
Revert to block-scoped namespaces
idg10 12455d7
Fix typos, standardized spelling of cancelled
idg10 a3be890
Merge branch 'main' into feature/takeuntil-update
idg10 389822a
Update release notes
idg10 2863dcd
Add UTF-8 BOM to release notes to make the umlaut work
idg10 d89901a
Fix the canceled-cancelled I missed before
idg10 3b87178
Add new TakeUntil to verified API
idg10 96ddb23
Add IQbservable form of TakeUntil
idg10 9560f1e
Fix exception documentation on new and one existing TakeUntil overload
idg10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
Rx.NET/Source/src/System.Reactive/Linq/Observable/TakeUntilCancellationToken.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT License. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Reactive.Disposables; | ||
using System.Threading; | ||
|
||
namespace System.Reactive.Linq.ObservableImpl | ||
{ | ||
/// <summary> | ||
/// Relays items to the downstream until the CancellationToken is cancelled. | ||
/// </summary> | ||
/// <typeparam name="TSource">The element type of the sequence</typeparam> | ||
internal sealed class TakeUntilCancellationToken<TSource> : | ||
Producer<TSource, TakeUntilCancellationToken<TSource>._> | ||
{ | ||
private readonly IObservable<TSource> _source; | ||
private readonly CancellationToken _token; | ||
|
||
public TakeUntilCancellationToken(IObservable<TSource> source, CancellationToken token) | ||
{ | ||
_source = source; | ||
_token = token; | ||
} | ||
|
||
protected override _ CreateSink(IObserver<TSource> observer) => new(observer); | ||
|
||
protected override void Run(_ sink) => sink.Run(this); | ||
|
||
internal sealed class _ : IdentitySink<TSource> | ||
{ | ||
private SingleAssignmentDisposableValue _cancellationTokenRegistration; | ||
private int _wip; | ||
private Exception? _error; | ||
|
||
public _(IObserver<TSource> observer) : base(observer) | ||
{ | ||
} | ||
|
||
public void Run(TakeUntilCancellationToken<TSource> parent) | ||
{ | ||
if (parent._token.IsCancellationRequested) | ||
{ | ||
OnCompleted(); | ||
return; | ||
} | ||
|
||
_cancellationTokenRegistration.Disposable = parent._token.Register(OnCompleted); | ||
Run(parent._source); | ||
} | ||
|
||
protected override void Dispose(bool disposing) | ||
{ | ||
if (disposing) | ||
{ | ||
_cancellationTokenRegistration.Dispose(); | ||
} | ||
base.Dispose(disposing); | ||
} | ||
|
||
public override void OnNext(TSource value) | ||
{ | ||
HalfSerializer.ForwardOnNext(this, value, ref _wip, ref _error); | ||
} | ||
|
||
public override void OnError(Exception error) | ||
{ | ||
HalfSerializer.ForwardOnError(this, error, ref _wip, ref _error); | ||
} | ||
|
||
public override void OnCompleted() | ||
{ | ||
HalfSerializer.ForwardOnCompleted(this, ref _wip, ref _error); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.