2

regarding to the following topic: https://stackoverflow.com/a/39960980/4457758

how can I adjust this flow for multiple incoming events which are depending lets say on a given object id ... So I am getting a bunch of events with different object ids and I want to debounce them for every target object Id every xxx milli seconds? So I need for every object id a separate debouncer responsible only for one object id?

ArgV
  • 175
  • 3
  • 13

1 Answers1

3

You can use groupBy to group incoming events by some parameter. Then debounce each group separately.

import { timer } from 'rxjs';
import { debounce, mergeMap, groupBy } from 'rxjs/operators';

eventStream$.pipe(
  groupBy(event => event.id),
  mergeMap(group$ => group$.pipe(
    debounce(event => timer(idToMillis(event.id)))
  ))
)
frido
  • 13,065
  • 5
  • 42
  • 56