GetStream / stream-video-js

GetStream JavaScript Video SDK
https://getstream.io/video/sdk/
Other
57 stars 19 forks source link

feat: add concurrency helpers #1392

Closed myandrienko closed 3 weeks ago

myandrienko commented 3 weeks ago

Adds three concurrency helpers:

  1. withoutConcurrency - accepts async functions and makes sure they run one after another, and never in parallel.
  2. withCancelation - does the same thing, but also cancels all other async functions when a new function is scheduled. Useful for actions that override each other, like enabling and disabling camera.
  3. createSafeAsyncSubscription adds an async listener to an Rx observable, and makes sure listeners never run in parallel, even if updates come in quicker than handlers can run.

As an example, those utilities are adopted in two places, where ad-hoc solutions were previously added: https://github.com/GetStream/stream-video-js/pull/1371 https://github.com/GetStream/stream-video-js/pull/1342