async_whilst: Repeatedly call task, while test returns true

View source: R/whilst.R

async_whilstR Documentation

Repeatedly call task, while test returns true

Description

Repeatedly call task, while test returns true

Usage

async_whilst(test, task, ...)

Arguments

test

Synchronous test function.

task

Asynchronous function to call repeatedly.

...

Arguments to pass to task.

Value

Deferred value, that is resolved when the iteration is done.

See Also

Other async control flow: async_backoff(), async_reflect(), async_retry(), async_retryable(), async_sequence(), async_try_each(), async_until()

Examples

## Keep calling while result is bigger than 0.1
calls <- 0
number <- Inf
synchronise(async_whilst(
  function() number >= 0.1,
  function() {
    calls <<- calls + 1
    number <<- runif(1)
  }
))
calls

r-lib/async documentation built on March 24, 2024, 6:20 p.m.