then-all-in
Constructs a promise for an object whose values are promises.
Last updated 7 years ago by kitcambridge .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install then-all-in 
SYNC missed versions from official npm registry.

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

Example

var allIn = require('then-all-in');

app.patch('/account/:id', function(request, response, next) {
    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);
});

License

MIT.

Current Tags

  • 0.2.0                                ...           latest (7 years ago)

2 Versions

  • 0.2.0                                ...           7 years ago
  • 0.1.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (3)
Dev Dependencies (5)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |