【发布时间】:2021-06-19 22:03:29
【问题描述】:
在 rxjs 中,如果调用了complete 方法,我应该也调用 unsubscribe 吗?
例如,我有一个来自 rxjs 的 timer,我设置为 5 秒。
在调用订阅函数后,我是否也应该从计时器中取消订阅?
import { timer } from "rxjs";
const token = timer(5 * 1000).subscribe({
next: () => {
console.log("xxx");
token.unsubscribe(); // <---- should I do it to to free memory?
},
complete: () => {
console.log("aaa");
}
});
【问题讨论】:
标签: rxjs