Handling Cleanup in Stream.flatMap with `{ switch: true }`
How to do "cleanup" in Stream.flatMap when using it with
Usecase:
Say there is an input field, which accepts user input and turns it into a
However, if a new input arrives when some of the validations are still running, we should cancel them and start over with the new input.
{ switch: true }?Usecase:
Say there is an input field, which accepts user input and turns it into a
Stream<never, never, input>. And whenever the input changes (debounced), we run multiple asynchronous validations on the input value in parallel. In order to show the validation result as quickly as possible, we emit new value on the resulting stream whenever any validation process resolves a result.However, if a new input arrives when some of the validations are still running, we should cancel them and start over with the new input.
