Skip to content

Commit

Permalink
This seems happier. I'm not 100% confident in this, but it's closer. …
Browse files Browse the repository at this point in the history
…R CMD check still chokes on test-async for me, though.
  • Loading branch information
jonthegeek committed Aug 16, 2024
1 parent d969bca commit 3b55162
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export(repo_get)
export(repo_resolve)
export(repo_status)
export(with_repo)
if (getRversion() >= "4.0.0") importFrom(tools, R_user_dir)
importFrom(R6,R6Class)
importFrom(tools,file_ext)
importFrom(utils,URLencode)
Expand Down
6 changes: 5 additions & 1 deletion R/aaa-async.R
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ async_env <- new.env(parent = emptyenv())
async_env$loops <- list()

get_default_event_loop <- function() {
num_loops <- length(async_env$loops)
num_loops <- length2(async_env$loops)
if (num_loops == 0) {
err <- make_error(
"You can only call async functions from an async context",
Expand All @@ -321,6 +321,10 @@ get_default_event_loop <- function() {

async_env$loops[[num_loops]]
}
# Mockable version of length.
length2 <- function(x) {
length(x)
}

push_event_loop <- function() {
num_loops <- length(async_env$loops)
Expand Down
2 changes: 2 additions & 0 deletions R/cache-dirs.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ win_path_local <- function() {

if (getRversion() < "4.0.0") {
R_user_dir <- my_R_user_dir
} else {
R_user_dir <- tools::R_user_dir
}

cleanup_old_cache_dir <- function(force = FALSE) {
Expand Down
10 changes: 4 additions & 6 deletions R/mocks.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# Define these objects so they can be mocked in tests.
interactive <- interactive
interactive <- base::interactive
readline <- function(prompt = "") {
readline
base::readline(prompt = prompt)
}
length <- length
Sys.info <- function() {
Sys.info
base::Sys.info()
}
R_user_dir <- R_user_dir
getRversion <- getRversion
getRversion <- base::getRversion
2 changes: 1 addition & 1 deletion tests/async/test-synchronise.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

test_that("error if async function is called from sync context", {

local_mocked_bindings(length = function(...) 0)
local_mocked_bindings(length2 = function(x) 0)
expect_error(
get_default_event_loop(),
class = "async_synchronization_barrier_error")
Expand Down

0 comments on commit 3b55162

Please sign in to comment.