@@ -657,6 +657,47 @@ module HighPriority =
657
657
sm.Data.current <- ValueNone
658
658
false )
659
659
660
+ member inline _.Bind
661
+ (
662
+ myAsync : Async < 'TResult1 >,
663
+ continuation : ( 'TResult1 -> ResumableTSC < 'T >)
664
+ ) : ResumableTSC < 'T > =
665
+ ResumableTSC< 'T>( fun sm ->
666
+ let mutable awaiter =
667
+ Async
668
+ .StartAsTask( myAsync, 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
+
696
+ member inline _.Bind ( myToken : CancellationToken , continuation : ( unit -> ResumableTSC < 'T >)) : ResumableTSC < 'T > =
697
+ ResumableTSC< 'T>( fun sm ->
698
+ sm.Data.cancellationToken <- myToken
699
+ ( continuation ()) .Invoke(& sm))
700
+
660
701
[<AutoOpen>]
661
702
module TaskSeqBuilder =
662
703
/// Builds an asynchronous task sequence based on IAsyncEnumerable<'T> using computation expression syntax.
0 commit comments