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

Multiple active plans (or connections?) / beeping when resolved #247

Closed
burchill opened this issue Aug 24, 2018 · 2 comments
Closed

Multiple active plans (or connections?) / beeping when resolved #247

burchill opened this issue Aug 24, 2018 · 2 comments

Comments

@burchill
Copy link

I'll admit, this is a bit weird, so please bear with me. I've been trying to make code so that when a remote future is resolved, a beep (simply beepr::beep()) will play.

I could obviously do:

while(!resolved(aFuture))
    Sys.sleep(1)
beepr::beep()

but I'd like to have it so that I'd be able to use the console for other things in the meantime.

My first thought was to make another future to take care of this, but the only future I found that would play audio over my computer was multisession, like so:

f <- function() {
  dont_care <- future({Sys.sleep(3); beepr::beep(1); "Nothing"})
}
f()

I also realized that you can't pass a future to another future (to check and wait until the first is resolved before beeping), so my next plan was to make a function that would take an expression, temporarily wrap the current plan in a multisession plan, embed the expression in another future and wait for the embedded future to resolve, make a ding, and then resolve the multisession future.

Unfortunately, I realize that the recommended

oplan <- plan()
on.exit(plan(oplan), add = TRUE)

bit would screw things up, since once the function had made the assignment, the multisession plan would be changed to what it was previously, and doing so would basically kill the multisession future. I.e.:

plan(multisession)
m1 <- future({Sys.sleep(10); "m1"})
plan(multicore)
resolved(m1)
# Error in socketSelect(list(con), write = FALSE, timeout = timeout) : 
#   invalid connection

(Oddly enough, switching the placement of plan(multisession) and plan(multicore) doesn't cause the same error, presumably because of something with multicore not using the same kind of connections?)

Anyway, is it somehow possible to get a plan that will keep running its code even if you switch to a different plan? Barring that, is there anything I can do to get a "beep on resolution" that lets me not have to permanently alter the current global plan?

Thanks!

@HenrikBengtsson
Copy link
Collaborator

What would really help you is something like:

f <- future({ ... }, hooks = list(onResolved = { beepr::beep() }))

Unfortunately, that's yet to be implemented. It's on the todo list (#172) as part of providing a framework for providing progress updates and likes.

@burchill
Copy link
Author

Ooooooh, that would be beautiful! Looks like you have a lot of great ideas in the works!

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

2 participants