tests/async/test-each-of.R

test_that("each_of", {

  done <- character()
  index <- integer()

  coll <- letters[1:10]

  do <- async(function() {
    dx <- when_all(
      .list = lapply(seq_along(coll), function(i) {
        force(i)
        delay(1/1000)$then(function(value) {
          done <<- c(done, coll[[i]])
          index <<- c(index, i)
        })
      })
    )$then(function(value) {
      expect_identical(sort(index), seq_along(coll))
      expect_identical(sort(done), sort(coll))
    })
  })
  synchronise(do())
})

Try the pkgcache package in your browser

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

pkgcache documentation built on July 26, 2023, 5:44 p.m.