官术网_书友最值得收藏!

Acting when an error occurs

In the previous sections, we saw how to encapsulate an error on bacon.js. Now, we will use the OnError() method to take an action whenever this happens. This method has the same signature as that of the onValue() method and works similarly, but only for bacon errors. Now with this method, we can change the code we used in the previous section to print an error when it occurs. This is shown as follows:

var myCustomEventStream = Bacon.fromBinder(function(push){ 
push('some value');
push('other value');
push(new Bacon.Error('NOW AN ERROR HAPPENED'));
push('Now the stream will finish');
push(new Bacon.End());
});
myCustomEventStream
.onError((value)=>
console.log(value)
);

It will print the following:

    NOW AN ERROR HAPPENED
As you might expect, the OnError() method also returns a function to unsubscribe.
主站蜘蛛池模板: 万宁市| 三明市| 左权县| 大石桥市| 龙山县| 济阳县| 紫云| 渝中区| 启东市| 汽车| 土默特左旗| 武川县| 桂平市| 翁牛特旗| 康乐县| 徐汇区| 光泽县| 兴义市| 自贡市| 中山市| 马尔康县| 苗栗市| 罗江县| 竹溪县| 金华市| 博湖县| 平利县| 六盘水市| 绥江县| 全州县| 衡阳市| 绵阳市| 怀仁县| 安化县| 元阳县| 晋中市| 合阳县| 仪征市| 钟山县| 砀山县| 滕州市|