RxJS - take n last elements from an observable

前端 未结 2 841
伪装坚强ぢ
伪装坚强ぢ 2021-02-13 13:20

I want to take 3 last elements from an observable. Let\'s say that my timeline looks like this:

--a---b-c---d---e---f-g-h-i------j->

where:

2条回答
  •  感情败类
    2021-02-13 13:27

    You can look at Observable#bufferCount function. One difference is that it wants at least 3 times to emit (first parameter, in this example).

    const source = Rx.Observable.interval(1000);
    const example = source.bufferCount(3,1)
    const subscribe = example.subscribe(val => console.log(val));

提交回复
热议问题