Created
February 9, 2020 22:22
-
-
Save TheFo2sh/b9e15108e399a0c88fbc2294a7ddd6c9 to your computer and use it in GitHub Desktop.
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
public class ObservableCancellationTokenSource<T> : CancellationTokenSource,IDisposable | |
{ | |
private readonly IDisposable _subscription; | |
public ObservableCancellationTokenSource(IObservable<T> observable) | |
{ | |
_subscription = observable.Subscribe(token=>this.Cancel()); | |
} | |
public new void Dispose() | |
{ | |
_subscription.Dispose(); | |
base.Dispose(); | |
} | |
} | |
public static class Extension | |
{ | |
public static ObservableCancellationTokenSource<T> ToCancellationTokenSource<T>(this IObservable<T> source) | |
{ | |
return new ObservableCancellationTokenSource<T>(source); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment