Skip to content

Commit

Permalink
Create final wait_stream using yielder.yield
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephTLyons committed Nov 27, 2024
1 parent fa89bbc commit b323722
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/persevero.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down

0 comments on commit b323722

Please sign in to comment.