当前位置:网站首页>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边栏推荐
- 外包幹了三年,廢了...
- 4、 High performance go language release optimization and landing practice youth training camp notes
- Interviewer: what development models do you know?
- Music | cat and mouse -- classic not only plot
- OOM(内存溢出)造成原因及解决方案
- [2022 ACTF]web题目复现
- 抽絲剝繭C語言(高階)指針的進階
- Talk about seven ways to realize asynchronous programming
- MySQL service is missing from computer service
- URP - shaders and materials - simple lit
猜你喜欢
Academic report series (VI) - autonomous driving on the journey to full autonomy
Lm11 reconstruction of K-line and construction of timing trading strategy
Robot technology innovation and practice old version outline
ROS2规划系统plansys2简单的例子
Cloud backup project
$refs: get the element object or sub component instance in the component:
Dynamics CRM server deployment - restore database prompt: the database is in use
Outsourcing for four years, abandoned
外包干了四年,废了...
Detailed explanation of neo4j installation process
随机推荐
Leetcode-206. Reverse Linked List
Flutter riverpod is comprehensively and deeply analyzed. Why is it officially recommended?
Robot technology innovation and practice old version outline
抽丝剥茧C语言(高阶)指针的进阶
聊聊异步编程的 7 种实现方式
Make a bat file for cleaning system garbage
JS decorator @decorator learning notes
How to reduce inventory with high concurrency on the Internet
二、并发、测试笔记 青训营笔记
PostgreSQL source code (59) analysis of transaction ID allocation and overflow judgment methods
Leetcode-226. Invert Binary Tree
记一个并发规则验证实现
2、 Concurrent and test notes youth training camp notes
Academic report series (VI) - autonomous driving on the journey to full autonomy
Redis data migration
弹性布局(一)
Select the product attribute pop-up box to pop up the animation effect from the bottom
外包干了三年,废了...
Explain Bleu in machine translation task in detail
Bi she - college student part-time platform system based on SSM