Promise.all
在 ramda 管道函数中的使用方式是怎样的?我认为我可能漏掉了些小细节。const pipeline: Function = R.pipe(
R.map((record) => record.body),
R.map(JSON.parse),
R.map(asyncFunction),
console.log
);
返回一个 promise 数组(
Promise.all
的输入参数)。[ Promise { <pending> },
Promise { <pending> },
Promise { <pending> },
Promise { <pending> },
Promise { <pending> },
Promise { <pending> },
Promise { <pending> },
Promise { <pending> },
Promise { <pending> },
Promise { <pending> } ]
但是,如果我尝试使用Promise.all
等待这些承诺被解决,就像这样:
const pipeline: Function = R.pipe(
R.map((record) => record.body),
R.map(JSON.parse),
R.map(asyncFunction),
Promise.all,
R.andThen(useTheReturn)
);
我最后遇到了一个类型错误,指出我正在尝试将Promise.all
作为构造函数类型使用。
{
"errorType": "TypeError",
"errorMessage": "#<Object> is not a constructor",
"stack": [
"TypeError: #<Object> is not a constructor",
" at all (<anonymous>)",
" at /var/task/node_modules/ramda/src/internal/_pipe.js:3:14",
" at /var/task/node_modules/ramda/src/internal/_arity.js:11:19",
" at Runtime.exports.handler (/var/task/lambda/data-pipeline/1-call-summary-ingestion/index.js:14:19)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)"
]
}
Promise.all
的上下文在这里切换并且必须显式设置回Promise
? - Mmm DonutsR.andThen(console.log)
函数仍然返回一个挂起的 Promise (非常奇怪)。 - Mmm Donutsconsole.log
的情况下该值为undefined
。 - Ori Drori