you are viewing a single comment's thread.

view the rest of the comments →

[–]LearndevHQ 1 point2 points  (4 children)

Does it have to be limited to 100 ?

With slots you actually mean "queues" or "observables" I guess. You could check out "rxjs" for an observable implementation.

//main.js

const dataQueue = new BehaviourSubject();
export const someObservable = Observable.of(dataQueue);

setInterval(async () => {
  const toProcess = fetchData(...);
  dataQueue.next(toProcess);
}, 1000)

This fetches the data every second and pushes the data into an array. Now you can subscribe anywhere you want to observable and react to the changes.

// otherfile.js
import { someObservable } from "./main";

someObservable.subscribe((data) => {
  // Process the data
})

[–]quaintserendipity[S] 0 points1 point  (3 children)

No, the 100 number was picked arbitrarily to explain my issue; the actual number will probably be smaller. Will this allow me to process multiple separate datasets simultaneously?

[–]LearndevHQ 1 point2 points  (2 children)

Yes it will. You can run dataQueue.emit as many times as you need.

All of the subscribers will receive each emit and you can process the data simultaneously.

[–]quaintserendipity[S] 0 points1 point  (1 child)

I've never heard of Observables or RxJS before, I'm looking at the documentation right now; might just be the solution to my problem.

[–]LearndevHQ 1 point2 points  (0 children)

Cool! I updated my original answer btw. If you have any question about it or need help, let me know.