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?

2
  • 2
    post your code... Commented Mar 29, 2020 at 16:20
  • 2
    I think you can use debounce for this: src$.pipe(debounce(({ id }) => timer(getTimeForId(id)))) Commented Mar 29, 2020 at 17:06

1 Answer 1

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)))
  ))
)
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks :) groupBy was the operator I was looking for :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.