Reputation: 367
In the following, I do not understand why the code blocks. I am expecting that printing "boom" should happen straight away, before printing "after Sys.sleep". I thought everything inside the future_promise expression should not cause blocking. What am I misunderstanding?
library(promises)
test <- function() {
promise <- future_promise({
Sys.sleep(10)
print("after Sys.sleep")
})
print("boom")
}
test()
Ok, this does what I was after!:
library(promises)
plan(multiprocess)
test2 <- function() {
future({
# expensive operations go here...
Sys.sleep(10)
}) %...>% (function(result) {
print("after Sys.sleep")
})
print("boom")
}
test2()
Upvotes: 2
Views: 124
Reputation: 367
This does what I was expecting:
library(promises)
plan(multiprocess)
test2 <- function() {
future({
Sys.sleep(10)
}) %...>% (function(result) {
print("after Sys.sleep")
})
print("boom")
}
test2()
Upvotes: 1