2

I have some code like so:

var downloadFiles = function () {
        console.log('downloading files');
        aFtpClient.
        listAsync().
        then(processListing).
        map(function (object) {
            return processItem(object);
        }).
        then(downloadItem).
        catch (TypeError, function (e) {
            console.dir('arse' + e);
        }).
        catch (Promise.RejectionError, function (e) {
            console.error("unable to read file, because: ", e.message);
        });
        console.log('after downloading files');
    };

processListing returns an array of objects with source & destination properties. I use map to deal with the array and call processItem. Is there a way to pass the mapped object to downloadItem?

4

1 回答 1

2

我会去

.map(function (object) {
    return processItem(object).then(function(processResult) {
        return {input: object, result: processResult};
    });
})

现在downloadItem可以同时访问.input每个.result已处理的项目。

于 2014-03-16T20:59:00.563 回答