从承诺链到Rx.js

时间:2016-02-10 16:49:55

标签: javascript promise bluebird rxjs

我有一个类似下面的承诺链,其中有三个承诺。我现在一直在研究Rx.js,在将这些承诺转换为可观察对象并将这些信息链接到不同的函数时,我无法弄清楚从哪里开始。如果可能的话,我真的很感激一些指导/知识。

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})
    })
  })
}

1 个答案:

答案 0 :(得分:0)

正如Ben在他的评论中所提到的,RxJs中的一些运算符接受了承诺并隐含地将它们转换为可观察的。关于承诺链,以下是两个可以帮助您进一步理解的资源。第一个涉及链接,第二个涉及链接,但侧重于错误管理:

相关问题