Skip to contents

Decorator that runs the function on its first successful call and returns that result on every call after it, ignoring later arguments. An error stores nothing, so the next call tries again. Unlike cache, it keeps one result whatever the arguments.

Usage

once(f)

Arguments

f

The function to decorate. Usually supplied by %@% rather than directly.

Value

A decorator.

Details

For a function that returns a promise, use async_once(), which also does not store a rejection.

Examples

setup := once %@% function() {
  cat("setting up\n")
  42
}
setup()
#> setting up
#> [1] 42
setup() # no output, same result
#> [1] 42