r - 为什么这个承诺会导致 R 中的阻塞?
问题描述
在下面,我不明白为什么代码块。我希望在打印“Sys.sleep 之后”之前立即打印“繁荣”。我认为 future_promise 表达式中的所有内容都不应导致阻塞。我有什么误解?
library(promises)
test <- function() {
promise <- future_promise({
Sys.sleep(10)
print("after Sys.sleep")
})
print("boom")
}
test()
好的,这就是我所追求的!:
library(promises)
plan(multiprocess)
test2 <- function() {
future({
# expensive operations go here...
Sys.sleep(10)
}) %...>% (function(result) {
print("after Sys.sleep")
})
print("boom")
}
test2()
解决方案
这符合我的预期:
library(promises)
plan(multiprocess)
test2 <- function() {
future({
Sys.sleep(10)
}) %...>% (function(result) {
print("after Sys.sleep")
})
print("boom")
}
test2()
推荐阅读
- python - IP 地址直方图(熊猫系列)
- amazon-web-services - 为具有 CloudFormation 更改集的正在运行的集群启用 AWS Redshift 加密
- rest - 即使我已注销,如何从 /admin/products.json 获取数据(所以普通访问者也可以看到数据)?
- javascript - React Native 中心动画图标
- amazon-web-services - SignatureDoesNotMatch when accessing the S3 pre-signed url
- liferay - Liferay 7 - 显示本地化数据
- python - lmfit 复合函数,可能具有不同的函数形式
- c# - 为什么我的一对多字段没有保存在数据库中
- conv-neural-network - 用于输出的 Keras 2D 密集层
- javascript - getJSON 返回 200 但错误