特定
let arr = [1,2,3];
function filter(num) {
return new Promise((res, rej) => {
setTimeout(() => {
if( num === 3 ) {
res(num);
} else {
rej();
}
}, 1);
});
}
function filterNums() {
return Promise.all(arr.filter(filter));
}
filterNums().then(results => {
let l = results.length;
// length should be 1, but is 3
});
Run Code Online (Sandbox Code Playgroud)
长度为3,因为返回了Promises,而不是值.有没有办法用返回Promise的函数过滤数组?
注意:对于此示例,fs.stat已替换为setTimeout,请参阅https://github.com/silenceisgolden/learn-esnext/blob/array-filter-async-function/tutorials/array-filter-with-async- function.js用于特定代码.
当我尝试从gcloud CLI部署时,我收到以下错误.
Copying files to Google Cloud Storage...
Synchronizing files to [gs://staging.logically-abstract-www-site.appspot.com/].
Updating module [default]...\Deleted [https://www.googleapis.com/compute/v1/projects/logically-abstract-www-site/zones/us-central1-f/instances/gae-builder-vm-20151030t150724].
Updating module [default]...failed.
ERROR: (gcloud.preview.app.deploy) Error Response: [4] Timed out creating VMs.
Run Code Online (Sandbox Code Playgroud)
我的app.yaml是:
runtime: nodejs
vm: true
api_version: 1
automatic_scaling:
min_num_instances: 2
max_num_instances: 20
cool_down_period_sec: 60
cpu_utilization:
target_utilization: 0.5
Run Code Online (Sandbox Code Playgroud)
我已成功登录并拥有正确的项目ID.我看到在App Engine的云控制台中创建了新版本,但错误似乎就在此之后.
在stdout日志中,我看到两个实例都跟上了我在应用程序开始监听端口后放入应用程序的最后一个console.log语句,但是在shutdown.log中我看到"app is unhealthy",在syslog中我看到"警告" :从来没有得到应用程序的健康响应,但无论如何发送/ _ah/start查询."
google-app-engine node.js gcloud managed-vm google-managed-vm