문제

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?

도움이 되었습니까?

해결책

I'd go with

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

Now downloadItem can access both .input and .result of each processed item.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top