tests/testthat/test-constant.R

test_that("creates a deferred value", {
  do <- function() {
    dx <- async_constant()
    expect_true(is_deferred(dx))
    dx
  }
  synchronise(do())

  do <- function() {
    dx <- async_constant("foobar")
    expect_true(is_deferred(dx))
    dx
  }
  synchronise(do())
})

test_that("resolves to the specified value", {
  do <- function() {
    async_constant("foobar")$
      then(function(x) expect_equal(x, "foobar"))
  }
  synchronise(do())

  do <- function() {
    async_constant()$
      then(function(x) expect_null(x))
  }
  synchronise(do())
})
gaborcsardi/async documentation built on Nov. 20, 2024, 4:51 p.m.