From b3237221df72b25291f65c5206858f32b4c6be20 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Wed, 27 Nov 2024 11:04:49 -0500 Subject: [PATCH] Create final wait_stream using yielder.yield --- src/persevero.gleam | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/persevero.gleam b/src/persevero.gleam index 259e703..c33db98 100644 --- a/src/persevero.gleam +++ b/src/persevero.gleam @@ -135,10 +135,10 @@ pub fn execute_with_wait( case max_attempts <= 0 { True -> RetryData(result: Error(RetriesExhausted([])), wait_times: []) False -> { - let wait_stream = wait_stream |> yielder.take(max_attempts - 1) let wait_stream = - yielder.from_list([0]) - |> yielder.append(wait_stream) + wait_stream + |> yielder_prepend(0) + |> yielder.take(max_attempts) |> yielder.map(int.max(_, 0)) do_execute( @@ -155,6 +155,11 @@ pub fn execute_with_wait( } } +fn yielder_prepend(yielder: Yielder(a), element: a) -> Yielder(a) { + use <- yielder.yield(element) + yielder +} + fn do_execute( wait_stream wait_stream: Yielder(Int), allow allow: fn(b) -> Bool,