• bufferWhen
    • 签名: bufferWhen(closingSelector: function): Observable
  • 收集值,直到关闭选择器发出值才发出缓冲的值。
    • 示例
      • 示例 1: 发出基于 interval 缓冲的值
  • 其他资源

    bufferWhen

    签名: bufferWhen(closingSelector: function): Observable

    收集值,直到关闭选择器发出值才发出缓冲的值。

    bufferWhen - 图1

    示例

    示例 1: 发出基于 interval 缓冲的值

    ( StackBlitz | jsBin |
    jsFiddle )

    1. import { interval } from 'rxjs/observable/interval';
    2. import { bufferWhen } from 'rxjs/operators';
    3. // 每1秒发出值
    4. const oneSecondInterval = interval(1000);
    5. // 返回的 observable 每5秒发出值
    6. const fiveSecondInterval = () => interval(5000);
    7. // 每5秒发出缓冲的值
    8. const bufferWhenExample = oneSecondInterval.pipe(bufferWhen(fiveSecondInterval));
    9. // 输出值
    10. // 输出: [0,1,2,3]...[4,5,6,7,8]
    11. const subscribe = bufferWhenExample.subscribe(val =>
    12. console.log('Emitted Buffer: ', val)
    13. );

    其他资源

    • bufferWhen :newspaper: - 官方文档

    :file_folder: 源码: https://github.com/ReactiveX/rxjs/blob/master/src/internal/operators/bufferWhen.ts