0

I have a promise chain like the one below, that has three promises in it. I've been studying Rx.js for a bit now, and I can't figure out where to start when it comes to converting these promises to observables and chaining this information around into the different functions. I'd really appreciate some guidance / knowledge if it's even possible.

export function pushCustomers (mongo, shopify) {
  return getDocsWhereRequest(mongo, 'shopify_customers').map(customer => {
    return createCustomer (shopify, customer.shopifyRequest).then(shopifyResponse => {
      return updateCollection(mongo, 'shopify_customers', {email: customer.email}, {shopifyResponse})
    }).catch(err => {
      if (!_.get(err, 'response.body.errors')) throw err
      let shopifyResponseError = JSON.stringify(err.response.body.errors)
      return updateCollection(mongo, 'shopify_customers', {email: customer.email}, {shopifyResponseError})
    })
  })
}
ThomasReggi
  • 55,053
  • 85
  • 237
  • 424
  • You don't need to convert your promises code to Rx for the sake of conversion since Rx works just fine with promises and consumes them. – Benjamin Gruenbaum Feb 10 '16 at 18:32
  • Hey Ben! I'm having some issues running a big promise chain that moves a lot of data / throttles api's. I'd love to have a little more granularity, and learn Rx in the process. I'm looking for tutorials on Bluebird to Rx but I can't find anything that helps me grasp the concepts 1:1. – ThomasReggi Feb 10 '16 at 18:58

1 Answers1

0

As Ben mentioned in his comment, a few operators in RxJs accept promises and implicitly convert them into observables. About the promise chaining, following are two resources which should help you further your understanding. The first one deals with chaining, the second one also with chaining but focuses on error management :

Community
  • 1
  • 1
user3743222
  • 18,345
  • 5
  • 69
  • 75