File tree Expand file tree Collapse file tree 2 files changed +11
-0
lines changed
src/FSharp.Control.TaskSeq Expand file tree Collapse file tree 2 files changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -657,6 +657,12 @@ module HighPriority =
657
657
sm.Data.current <- ValueNone
658
658
false )
659
659
660
+ // Binding to a cancellation token. This allows `do! someCancellationToken`
661
+ member inline _.Bind ( myToken : CancellationToken , continuation : ( unit -> ResumableTSC < 'T >)) : ResumableTSC < 'T > =
662
+ ResumableTSC< 'T>( fun sm ->
663
+ sm.Data.cancellationToken <- myToken
664
+ ( continuation ()) .Invoke(& sm))
665
+
660
666
[<AutoOpen>]
661
667
module TaskSeqBuilder =
662
668
/// Builds an asynchronous task sequence based on IAsyncEnumerable<'T> using computation expression syntax.
Original file line number Diff line number Diff line change @@ -60,6 +60,11 @@ module internal TaskSeqInternal =
60
60
KeyNotFoundException( " The predicate function or index did not satisfy any item in the async sequence." )
61
61
|> raise
62
62
63
+ let inline withCancellationToken ( cancellationToken : CancellationToken ) ( source : taskSeq < 'T >) = taskSeq {
64
+ do ! cancellationToken
65
+ yield ! source
66
+ }
67
+
63
68
let isEmpty ( source : taskSeq < _ >) = task {
64
69
use e = source.GetAsyncEnumerator( CancellationToken())
65
70
let! step = e.MoveNextAsync()
You can’t perform that action at this time.
0 commit comments