-
Notifications
You must be signed in to change notification settings - Fork 35
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
Conversation
And only call it once, rather than once per evaluate call.
#' @return list containing four functions: `get_new`, `pause`, | ||
#' `unpause`, `close`. | ||
#' @keywords internal | ||
watchout <- function(debug = FALSE) { | ||
watchout <- function(handler = new_output_handler(), |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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.
R/watcher.R
Outdated
}, | ||
get_con = function() con | ||
) | ||
read_con <- function(con, buffer = 1024) { |
There was a problem hiding this comment.
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.
And only call it once, rather than once per evaluate call.