如何使用 redux-observable epic 测量 2 个动作之间的持续时间?

How can I measure the duration between 2 actions using redux-observable epic?

我正在尝试使用 redux-observable epic 测量 2 个动作的持续时间。

有一个相关的答案,但对我的情况没有帮助。 In redux-observable, how can I measure the epics duration time when running complete?

testeeEpic = action$ => action$.ofType('TEST_START', 'TEST_EMD')
  .pipe(
    // How to measure duration between 'TEST_START' and 'TEST_EMD'
  )

/*
`TEST_START` can be dispatched multiple times before `TEST_EMD`, 
duration between the lastest `TEST_START` and `TEST_EMD` is needed.
*/

如有帮助,将不胜感激

尝试 timeInterval -- 它测量两次发射之间的时间。

测量第一个 START 和下一个 END 之间的时间:

.pipe(
  distinctUntilChanged(),
  timeInterval(),
  filter(({ value }) => value !== START_EVENT),
  map(({ interval }) => interval)
)

Timespan between first START and next END example.

更新

测量最近 START 和后续 END 之间的时间:

.pipe(
  timeInterval(),
  pairwise(),
  filter(([first, second]) =>
    first.value === START_EVENT
    && second.value === END_EVENT
  ),
  map(([, second]) => second.interval)
)

Timespan between latest START and following END example.

希望对您有所帮助