Skip to content

Commit

Permalink
let async functions return invisibly
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Aug 21, 2024
1 parent c29ba7d commit c5b7f95
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/generator.R
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ generator0 <- function(fn, type = "generator") {
)
env$jumped <- FALSE

out
invisible(out)
})

env$.self <- instance
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-async.R
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,14 @@ test_that("can await-assign with `=` (#29)", {
})
expect_equal(wait_for(fn()), 2)
})

test_that("async function returns invisibly (#46)", {
out <- NULL
fn <- async(function() {
for (i in 1:3) {
out <<- c(out, i)
await(i)
}
})
expect_invisible(fn())
})

0 comments on commit c5b7f95

Please sign in to comment.