当前位置:网站首页>Rxjs - observable doesn't complete when an error occurs - rxjs - observable doesn't complete when an error occurs
Rxjs - observable doesn't complete when an error occurs - rxjs - observable doesn't complete when an error occurs
2022-07-07 07:34:00 【fyin1314】
problem :
When I create an observable from scratch, and have the observer error, then complete, the done part of the subscription never is invoked. When I create one from scratch observable And there are observer errors , Then when finished , The completed part of the subscription will never be called .
var observer = Rx.Observable.create(function(observer){ observer.onError(new Error('no!')); observer.onCompleted();})observer.subscribe( function(x) { console.log('succeeded with ' + x ) }, function(x) { console.log('errored with ' + x ) }, function() { console.log('completed') })
The output is: The output is :
errored with Error: no!
I'd expect it to be: I hope it is :
errored with Error: no!completed
If I change the code to invoke onNext instead of onError, the observable properly completes: If I change the code to call onNext instead of onError, be observable Will be completed correctly :
var observer = Rx.Observable.create(function(observer){ observer.onNext('Hi!'); observer.onCompleted();})observer.subscribe( function(x) { console.log('succeeded with ' + x ) }, function(x) { console.log('errored with ' + x ) }, function() { console.log('completed') })
I get the expected output: I get the expected output :
succeeded with Hi! completed
Why does it not complete when an error has occured? Why did it not complete when an error occurred ?
Solution :
Reference resources : https://stackoom.com/en/question/2Hkkh边栏推荐
猜你喜欢
Outlier detection technology of time series data
Non empty verification of collection in SQL
ROS2规划系统plansys2简单的例子
Example of Pushlet using handle of Pushlet
Flexible layout (I)
A concurrent rule verification implementation
The currently released SKU (sales specification) information contains words that are suspected to have nothing to do with baby
Bi she - college student part-time platform system based on SSM
我理想的软件测试人员发展状态
计算机服务中缺失MySQL服务
随机推荐
Leetcode-226. Invert Binary Tree
抽丝剥茧C语言(高阶)数据的储存+练习
Nesting and splitting of components
1140_ SiCp learning notes_ Use Newton's method to solve the square root
Modify the jupyter notebook file path
JS decorator @decorator learning notes
1、 Go knowledge check and remedy + practical course notes youth training camp notes
English translation is too difficult? I wrote two translation scripts with crawler in a rage
../ And/
聊聊异步编程的 7 种实现方式
C language (high-level) data storage + Practice
三、高质量编程与性能调优实战 青训营笔记
How can a 35 year old programmer build a technological moat?
[cloud native] how to give full play to memory advantage of memory database
The annual salary of general test is 15W, and the annual salary of test and development is 30w+. What is the difference between the two?
Robot technology innovation and practice old version outline
Differences between H5 architecture and native architecture
Initial experience of teambiion network disk (Alibaba cloud network disk)
Convolutional neural network -- understanding of pooling
Sqlmap tutorial (IV) practical skills three: bypass the firewall