简体   繁体   English

将takeUntil()与Observable一起使用 <void> ?

[英]Will takeUntil() work with Observable<void>?

The documentation says that takeUntil continues to emit values until the passed observable emits a value . 该文件说, takeUntil继续进行,直到通过观察到发射值发射值。 It doesn't say until subscribe is called. 直到订阅被调用时才说。

I'm wondering if the following is safe to do? 我想知道下面的做法是否安全?

const x = new Subject<void>();

async.pipe(takeUntil(x)).subscribe(()=>.....);

x.next(); // <-- no value

The alternative would be to emit some kind of value in x.next(true) . 另一种方法是在x.next(true)发出某种值。

Yes calling x.next() is safe. 是的,调用x.next()是安全的。 By inspecting the source code it can be seen that takeUntil does not use the value emitted from Observable x and simply calls complete() on the source Observable. 通过检查源代码 ,可以看出takeUntil没有使用Observable x发出的值,而只是在源Observable上调用complete()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM