tests/async/test-process.R

test_that("process", {
  px <- asNamespace("processx")$get_tool("px")

  afun <- async(function() {
    when_all(
      delay = delay(1 / 1000)$then(function(x) 1),
      process = run_process(px, c("outln", "foobar"))$then(
        function(x) str_trim(x$stdout)
      ),
      r_process = run_r_process(function() 2)$then(function(x) x$result)
    )
  })

  res <- synchronise(afun())

  expect_equal(
    res,
    list(delay = 1, process = "foobar", r_process = 2)
  )
})

test_that("process + http", {
  px <- asNamespace("processx")$get_tool("px")

  afun <- async(function() {
    when_all(
      delay = delay(1 / 1000)$then(function() 1),
      http = http_get(http$url("/status/418"))$then(function(x) x$status_code),
      process = run_process(px, c("outln", "foobar"))$then(
        function(x) str_trim(x$stdout)
      ),
      r_process = run_r_process(function() 2)$then(function(x) x$result)
    )
  })

  res <- synchronise(afun())

  expect_equal(
    res,
    list(delay = 1, http = 418, process = "foobar", r_process = 2)
  )
})

Try the pkgcache package in your browser

Any scripts or data that you put into this service are public.

pkgcache documentation built on June 8, 2025, 10:49 a.m.