then-all-in

Constructs a promise for an object whose values are promises.

then-all-in

then-all-in is an object-aware variant of then-all. The allIn function returns a promise that is fulfilled with a new object containing the fulfillment value of each object member, or rejected with the same reason as the first rejected promise. This form can be helpful for conditionally queueing asynchronous operations.

$ npm i then-all-in
var allIn = require('then-all-in');
 
app.patch('/account/:id', function(requestresponsenext) {
    var changes = {},
        body = request.body;
 
    // Assume `Account.get` constructs a promise for an account model. 
    var account = Account.get(request.params.id);
 
    if (body.email != account.email) {
        // Assume `#setEmail()` is asynchronous. 
        changes.email = account.setEmail(body.email);
    }
 
    if (body.phone != account.phone) {
        changes.phone = account.setPhone(body.phone);
    }
 
    allIn(changes).done(function() {
        response.send(204);
    }, next);
});

MIT.