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

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.
主站蜘蛛池模板: 眉山市| 玉树县| 鸡泽县| 和政县| 东乡县| 平乡县| 高淳县| 潍坊市| 哈巴河县| 宁陵县| 武陟县| 洛浦县| 吉林省| 益阳市| 东兰县| 象州县| 合川市| 龙川县| 桑植县| 太湖县| 景谷| 武强县| 北辰区| 和政县| 金溪县| 沈阳市| 廉江市| 盐津县| 都匀市| 安义县| 泗水县| 台中市| 贵溪市| 和顺县| 雷山县| 克东县| 临夏县| 灌阳县| 定西市| 讷河市| 修武县|