0

假设我希望 Stream 在某些情况下发出错误:

import xs from 'xstream'
//...
function transformBlah(blah) {
    if (blah.status >= 200 && blah.status < 300) {
        return blah.body
    } else {
        return new Error('I would like to send an error onto the Stream here')
    }
}
const blahTransformed$ = xs.create(new BlahProducer())
                           .map(transformBlah)
4

1 回答 1

0

我发现引发异常可以在rxjs和中实现这一点xstream

import xs from 'xstream'
//...
const blahTransformed$ = xs.create(new BlahProducer())
                           .map(blah => {
                               if (blah.status >= 200 && blah.status < 300) {
                                   return blah.body
                               } else {
                                   throw blah.status 
                               }
                           })

异常被 Observable 库捕获,并在 Stream 上发出错误。

于 2017-10-17T09:55:08.967 回答