| 1 |
describe("C++ interface", { |
| 2 |
env <- new.env() |
| 3 |
Rcpp::sourceCpp( |
| 4 |
system.file("promise_task.cpp", package = "promises"), |
| 5 |
env = env |
| 6 |
) |
| 7 |
|
| 8 |
it("basically works", { |
| 9 |
promise(function(resolve, reject) { |
| 10 |
env$asyncFib(resolve, reject, 3) |
| 11 |
}) |> |
| 12 |
then(\(x) { |
| 13 |
expect_identical(x, 2) |
| 14 |
}) |> |
| 15 |
wait_for_it() |
| 16 |
}) |
| 17 |
|
| 18 |
it("works with domains", { |
| 19 |
cd <- create_counting_domain() |
| 20 |
|
| 21 |
expect_true(is.null(current_promise_domain())) |
| 22 |
with_promise_domain(cd, { |
| 23 |
promise(function(resolve, reject) { |
| 24 |
env$asyncFib(resolve, reject, 3) |
| 25 |
}) |> |
| 26 |
then(\(x) { |
| 27 |
expect_identical(x, 2) |
| 28 |
expect_identical(cd$counts$onFulfilledCalled, 1L) |
| 29 |
promise_resolve(TRUE) |> |
| 30 |
then(\(y) { |
| 31 |
expect_true(!is.null(current_promise_domain())) |
| 32 |
expect_identical(cd$counts$onFulfilledCalled, 2L) |
| 33 |
}) |
| 34 |
}) |> |
| 35 |
wait_for_it() |
| 36 |
}) |
| 37 |
}) |
| 38 |
}) |