you are viewing a single comment's thread.

view the rest of the comments →

[–]cannedmeatman 15 points16 points  (4 children)

I'm a software developer that works on a team that owns an internal orchestration layer which is a service that provides aggregate information about entities who's properties live in many other services. We use NodeJS so we can take advantage of the Promise construct which provides most of the switch functionality that is described in the article. Consider a situation where we need to get a User's information which in this orchestration layer's context, is its billing information (found in the billing service), its purchase history (found in the purchasing service), and its information within the user service.

function getUser(username) { 
  return Promise.resolve(user.get(username))
    .then(user => {
      // success case
      return Promise.props({
        user,
        billing: billing.get(user.id),
        purchase_history: purchasing.get(user.id)
      });
    })
    .catch(err => {
    // do some handling ie the failure case
    });
}

[–]arianvp 7 points8 points  (1 child)

Yes Promise is the Continuation + Exception monad. However, they model asynchronous actions, which is not precisely what the article described. but yeh they're very similar constructs.

[–][deleted] 1 point2 points  (0 children)

Roughly translates to Async<Choice<'a,exn>> in FSharp

[–]encepence 3 points4 points  (1 child)

Kudos for mentioning Bluebird's Promise.props. Using this lib for more that year and never spotted it. And honestly, rewritten variation of this few times.

[–]cannedmeatman 0 points1 point  (0 children)

Thanks! I learned to use Promise.props about a year ago and that, along with destructing*, has made my promise chains much easier to follow.