sách gpt4 ai đã đi

Toán tử RxJS waitUntil

In lại 作者:行者123 更新时间:2023-12-04 01:15:27 30 4
mua khóa gpt4 Nike

a: 1---2-3-4--5---6
b: ------T---------

o: ------1234-5---6

使用RxJS,有没有什么算子可以完成上图?我有一个流 A,它是一个随机的事件流,给定一个流 B,它有一个 ĐÚNG VẬY事件,我可以有一个输出流,直到 ĐÚNG VẬY 才发出任何东西吗?事件,然后发送所有内容都已保存,然后再正常发出?

我想也许我可以用 buffer() ,但似乎没有办法用该运算符做这样的一次性缓冲区。

1 Câu trả lời

const { concat, interval, of, from } = rxjs;
const { share, delay, toArray, takeUntil, mergeMap } = rxjs.operators;

const waitUntil = signal$ => source$ => {
const sharedSource$ = source$.pipe(share());
return concat(
sharedSource$.pipe(
takeUntil(signal$),
toArray(),
mergeMap(from)
),
sharedSource$
);
}

const stopWaiting$ = of('signal').pipe(delay(2000));

const source$ = interval(500).pipe(
waitUntil(stopWaiting$)
).subscribe(console.log);

关于RxJS 操作符 waitUntil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54259886/

30 4 0
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com