Предисловие, я использую BlueBird, чтобы переписать код из обратных вызовов в Promises (Bluebird — это круто, кстати), и я пытаюсь реорганизовать свой код:
У меня есть функция, которая будет использоваться в другой ситуации, вот эта:
var getPackagesWithIndex = function(request, indexName, indexValue){
return new Promise(function(resolve, reject){
Package.query(indexValue).usingIndex(indexName).exec(
function(err, data){
if (err) return reject(err);
// Add the request to the payload
data.request_ota = request;
resolve(data);
});
})
}
Я связываю такие функции, чтобы получить желаемый результат:
var promote = function(request){
var destination_build = request.params.destination_build;
return sanitizeInput(request
).then(getPackagesWithIndex.bind(undefined, destination_build, 'destination_build')
).then(preparePackages
).mapSeries(updatePackage)
}
когда я console.log
результат, порядок аргументов кажется перепутанным: request
получил значение indexValue
, есть ли способ сохранить порядок?
request == request.params.destination_build
,indexName == 'destination_build'
иindexValue == resolved value of promise
, возвращаемыми в функцииsanitizeInput
- person Jaromanda X   schedule 09.11.2015