File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
src/FSharp.Control.TaskSeq Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -657,6 +657,42 @@ module HighPriority =
657
657
sm.Data.current <- ValueNone
658
658
false )
659
659
660
+ member inline _.Bind
661
+ (
662
+ asyncSource : Async < 'TResult1 >,
663
+ continuation : ( 'TResult1 -> ResumableTSC < 'T >)
664
+ ) : ResumableTSC < 'T > =
665
+ ResumableTSC< 'T>( fun sm ->
666
+ let mutable awaiter =
667
+ Async
668
+ .StartAsTask( asyncSource, cancellationToken = sm.Data.cancellationToken)
669
+ .GetAwaiter()
670
+
671
+ let mutable __stack_fin = true
672
+
673
+ Debug.logInfo " at Bind"
674
+
675
+ if not awaiter.IsCompleted then
676
+ // This will yield with __stack_fin2 = false
677
+ // This will resume with __stack_fin2 = true
678
+ let __stack_fin2 = ResumableCode.Yield() .Invoke(& sm)
679
+ __ stack_ fin <- __ stack_ fin2
680
+
681
+ Debug.logInfo ( " at Bind: with __stack_fin = " , __ stack_ fin)
682
+ Debug.logInfo ( " at Bind: this.completed = " , sm.Data.completed)
683
+
684
+ if __ stack_ fin then
685
+ Debug.logInfo " at Bind: finished awaiting, calling continuation"
686
+ let result = awaiter.GetResult()
687
+ ( continuation result) .Invoke(& sm)
688
+
689
+ else
690
+ Debug.logInfo " at Bind: await further"
691
+
692
+ sm.Data.awaiter <- awaiter
693
+ sm.Data.current <- ValueNone
694
+ false )
695
+
660
696
[<AutoOpen>]
661
697
module TaskSeqBuilder =
662
698
/// Builds an asynchronous task sequence based on IAsyncEnumerable<'T> using computation expression syntax.
Original file line number Diff line number Diff line change @@ -191,3 +191,5 @@ module HighPriority =
191
191
type TaskSeqBuilder with
192
192
193
193
member inline Bind : task : Task < 'TResult1 > * continuation : ( 'TResult1 -> ResumableTSC < 'T >) -> ResumableTSC < 'T >
194
+ member inline Bind :
195
+ asyncSource : Async < 'TResult1 > * continuation : ( 'TResult1 -> ResumableTSC < 'T >) -> ResumableTSC < 'T >
You can’t perform that action at this time.
0 commit comments