From ac58c65537d6d31a80e2253ae038c36a215f09fc Mon Sep 17 00:00:00 2001 From: Abel Braaksma Date: Tue, 19 Dec 2023 03:20:42 +0100 Subject: [PATCH] Fix `truncate`, do not `MoveNext` before we know we have enough elements --- src/FSharp.Control.TaskSeq/TaskSeqInternal.fs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/FSharp.Control.TaskSeq/TaskSeqInternal.fs b/src/FSharp.Control.TaskSeq/TaskSeqInternal.fs index 6704d868..9915f358 100644 --- a/src/FSharp.Control.TaskSeq/TaskSeqInternal.fs +++ b/src/FSharp.Control.TaskSeq/TaskSeqInternal.fs @@ -721,8 +721,12 @@ module internal TaskSeqInternal = while cont do yield e.Current pos <- pos + 1 - let! moveNext = e.MoveNextAsync() - cont <- moveNext && pos < count + + if pos < count then + let! moveNext = e.MoveNextAsync() + cont <- moveNext + else + cont <- false }