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 =
657657 sm.Data.current <- ValueNone
658658 false )
659659
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+
660666[<AutoOpen>]
661667module TaskSeqBuilder =
662668 /// 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 =
6060 KeyNotFoundException( " The predicate function or index did not satisfy any item in the async sequence." )
6161 |> raise
6262
63+ let inline withCancellationToken ( cancellationToken : CancellationToken ) ( source : taskSeq < 'T >) = taskSeq {
64+ do ! cancellationToken
65+ yield ! source
66+ }
67+
6368 let isEmpty ( source : taskSeq < _ >) = task {
6469 use e = source.GetAsyncEnumerator( CancellationToken())
6570 let! step = e.MoveNextAsync()
You can’t perform that action at this time.
0 commit comments