0

I have a stream that emits an array of values, which is aggregated as toggleable array values in a subject, i.e. a list of integers. I would like to emit only a specific value when a certain integer is given, then return to the list of integers after a timeout.

For example:

The specific value 3 -> [3]

Input: 1
Output: [1]
Input: 2
Output: [1,2]
Input: 3
Output: [3]
timeout (1 second)
Output: [1,2]
Input: 2
Output: [1]
Input: 2
Output: [1,2]

How can I accomplish this using a reactive extensions approach? I am looking to use rxpy for this application.

The current implementation to aggregate values is the following:

# input id
monitor_selected = self.monitor_selected_subject.pipe(ops.first()).run().copy()
if id in monitor_selected and not id.id == NexusChannelId.PRI_CHANNEL:
    monitor_selected.remove(id)
else:
    monitor_selected.append(id)
self.monitor_selected_subject.on_next(monitor_selected)
John Ericksen
  • 10,995
  • 4
  • 45
  • 75

0 Answers0