From 17641575034e735a27cae07a1fd12bf645aebead Mon Sep 17 00:00:00 2001 From: Abel Braaksma Date: Sat, 22 Oct 2022 04:22:24 +0200 Subject: [PATCH] Issue #39: several log statements added for analysing TaskSeqBuilder --- src/FSharpy.TaskSeq/TaskSeqBuilder.fs | 28 ++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/FSharpy.TaskSeq/TaskSeqBuilder.fs b/src/FSharpy.TaskSeq/TaskSeqBuilder.fs index 25b29d10..ec129536 100644 --- a/src/FSharpy.TaskSeq/TaskSeqBuilder.fs +++ b/src/FSharpy.TaskSeq/TaskSeqBuilder.fs @@ -153,8 +153,25 @@ and [] TaskSeq<'Machine, 'T member ts.GetResult(token: int16) = match ts.hijack () with - | Some tg -> (tg :> IValueTaskSource).GetResult(token) - | None -> ts.Machine.Data.promiseOfValueOrEnd.GetResult(token) + | Some tg -> + if verbose then + printfn "Getting result for token on 'Some' branch: %i" token + + (tg :> IValueTaskSource).GetResult(token) + | None -> + try + if verbose then + printfn "Getting result for token on 'None' branch: %i" token + + ts.Machine.Data.promiseOfValueOrEnd.GetResult(token) + with e -> + // FYI: an exception here is usually caused by the CE statement (user code) throwing an exception + // We're just logging here because the following error would also be caught right here: + // "An attempt was made to transition a task to a final state when it had already completed." + if verbose then + printfn "Error '%s' for token: %i" e.Message token + + reraise () member ts.OnCompleted(continuation, state, token, flags) = match ts.hijack () with @@ -165,7 +182,12 @@ and [] TaskSeq<'Machine, 'T member ts.MoveNext() = match ts.hijack () with | Some tg -> (tg :> IAsyncStateMachine).MoveNext() - | None -> MoveNext(&ts.Machine) + | None -> + printfn "Before: resumption point: %A" ts.Machine.ResumptionPoint + printfn "Before: machine data: \n%A" ts.Machine.Data + MoveNext(&ts.Machine) + printfn "After: resumption point: %A" ts.Machine.ResumptionPoint + printfn "After: machine data: \n%A" ts.Machine.Data member _.SetStateMachine(_state) = () // not needed for reference type