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

Make watcher more simpler and more self-contained #149

Merged
merged 5 commits into from
Jun 18, 2024
Merged

Make watcher more simpler and more self-contained #149

merged 5 commits into from
Jun 18, 2024

Conversation

hadley
Copy link
Member

@hadley hadley commented Jun 18, 2024

And only call it once, rather than once per evaluate call.

And only call it once, rather than once per evaluate call.
@hadley hadley requested a review from cderv June 18, 2024 12:28
#' @return list containing four functions: `get_new`, `pause`,
#' `unpause`, `close`.
#' @keywords internal
watchout <- function(debug = FALSE) {
watchout <- function(handler = new_output_handler(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is technically a breaking change, but (unsurprisingly) I don't see any evidence that anyone has ever used it. It might be worth un-exporting in the next version to make it very clear that it's for internal use only.

watchout <- function(handler = new_output_handler(),
debug = FALSE,
frame = parent.frame()) {
con <- file("", "w+b")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A file() connection takes a bit longer to set up than a text connection, but it is faster to append too (especially as the output grows long since appending to a character vector is O(n^2)). It's also simpler and faster to read from, and any set up time is now amortised over all top level expressions.

@hadley hadley requested a review from gaborcsardi June 18, 2024 13:25
R/watcher.R Outdated
},
get_con = function() con
)
read_con <- function(con, buffer = 1024) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can read more bytes from the buffer, e.g. 32k seems like a good number that allows a single read operation often.

@hadley hadley merged commit 4d22a38 into main Jun 18, 2024
13 checks passed
@hadley hadley deleted the watcher branch June 18, 2024 17:28
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

Successfully merging this pull request may close these issues.

3 participants