Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top