【发布时间】:2018-03-14 05:35:27
【问题描述】:
我正在编写一个具有以下流程的软件:
Promise.resolve(updateMongoStatus)
.then(unzipFilesFromS3)
.then(phase4) //example
.then(phase5) //example
.then(processSomething)
.catch(saveErrorToMongo)
我想知道是否可以将数据从第一个函数传递到最后一个函数,例如:
function updateMongoStatus() {
// do something here that updates Mongo and get status of some document
return { status }
}
function unzipFilesFromS3({ status }) {
// do something here to unzip files from s3
return { status, files }
}
function phase4({ status, files }) {
// etc
}
直到processSomething 最终被调用:
function processSomething({ parameterFromOutputOfUpdateMongoStatus, parameterFromPhase4, parameterFromPhase5 }) {
// Do something here
}
这样好吗?像这样传递数据?
谢谢。
【问题讨论】:
-
是的,这完全没问题,虽然可能有simpler solutions to do that。
-
哇,这真是完美的贝尔吉!欧姆
-
只是一个提示,
Promise.resolve(updateMongoStatus)不会返回Promise<{ status }>而是Promise<Function>。你的意思可能是Promise.resolve().then(updateMongoStatus)
标签: javascript node.js promise execution