public void MergeNullSources_Fact() { CancellationSource.Merge(null, null) .ShouldBeNull(); CancellationSource.Merge(CancellationSource.Canceled, null) .ShouldEqual(CancellationSource.Canceled); CancellationSource.Merge(null, CancellationSource.Canceled) .ShouldEqual(CancellationSource.Canceled); }
public void MergeAndCancelSecond_Fact() { var source1 = new CancellationSource(); var source2 = new CancellationSource(); var merged = CancellationSource.Merge(source1, source2); source2.Cancel(); source1.IsCancelationRequested.ShouldBeFalse(); source2.IsCancelationRequested.ShouldBeTrue(); merged.IsCancelationRequested.ShouldBeTrue(); //ensure safety in calling other cancels source1.Cancel(); merged.Cancel(); }
public static CancellationSource operator +(CancellationToken token1, CancellationToken token2) { return(CancellationSource.Merge(token1._source, token2._source)); }