Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

service() fails to run inside later::with_temp_loop() #250

Open
RLesur opened this issue Nov 4, 2019 · 0 comments
Open

service() fails to run inside later::with_temp_loop() #250

RLesur opened this issue Nov 4, 2019 · 0 comments

Comments

@RLesur
Copy link

RLesur commented Nov 4, 2019

Originally posted in rstudio/pagedown#150

This issue is related to later >= 1.0.0 which introduces private event loops.

The first observation is that httpuv uses only the global event loop even if startServer() is called inside later::with_temp_loop().

The problem is that service() does not execute the callbacks registered in the global loop when called inside later::with_temp_loop().
This comes from the fact that later::run_now() executes the callbacks registered in the current loop.

httpuv/R/httpuv.R

Lines 588 to 615 in 57e1d71

service <- function(timeoutMs = ifelse(interactive(), 100, 1000)) {
# In all cases, call `run_now` with `all = FALSE` so that if there is a lot of
# incoming traffic (relative to the time it takes to process it) we give the
# owning event loop opportunities to do housekeeping in between httpuv related
# callbacks.
if (is.na(timeoutMs)) {
# NA means to run non-blocking
run_now(0, all = FALSE)
} else if (timeoutMs == 0 || timeoutMs == Inf) {
.globals$paused <- FALSE
# In interactive sessions, wait for a max of 0.1 seconds for better
# responsiveness when the user sends an interrupt (like Esc in RStudio.)
check_time <- if (interactive()) 0.1 else Inf
while (!.globals$paused) {
run_now(check_time, all = FALSE)
}
} else {
# No need to check for .globals$paused because if run_now() executes
# anything, it will return immediately.
run_now(timeoutMs / 1000, all = FALSE)
}
# Some code expects service() to return TRUE (#123)
TRUE
}

For now, the workaround is to use later::with_loop(later::global_loop(), httpuv::service()) instead of httpuv::service().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant