RXJS多播在NodeJ和浏览器中不一致的错误行为
const tick$ = interval(1000).pipe(take(10))
const subject = new Subject<number>()
tick$.subscribe(subject)
subject
.pipe(
map(x => {
if (x === 5) {
throw new Error('error!!!')
}
return x
})
)
.subscribe(x => console.log('x1: ', x))
subject.subscribe(x => console.log('x2: ', x))
上面的代码在浏览器中运行,当x === 5
时,只有x1
被中断,x2
可以继续,但是在nodejs中,X1
发生错误杀死了该过程。有人可以解释为什么?先感谢您!
const tick$ = interval(1000).pipe(take(10))
const subject = new Subject<number>()
tick$.subscribe(subject)
subject
.pipe(
map(x => {
if (x === 5) {
throw new Error('error!!!')
}
return x
})
)
.subscribe(x => console.log('x1: ', x))
subject.subscribe(x => console.log('x2: ', x))
Above code run in browser, when x === 5
, only x1
is interrupted and x2
can continue, but in nodejs, x1
occured error killed the process. Somebody can explain why? Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在nodejs中,当出现错误时,该过程将被杀死。
您应该总是这样做:
in nodejs the process is killed when there is an error.
you should always do it like this: