Transforming an array of numbers into observables that emit at random times is a task I have been working on.
Once all the observables are resolved, I display the final result.
To achieve this, I am utilizing forkJoin
, similar to how one would use promise.all
.
let arr: Array<Number> = [1, 2, 3, 4, 5];
let d = from(arr).pipe(mergeMap(f => myPromise(f)), toArray());
const example = forkJoin(d);
const subscribe = example.subscribe(val => console.log(val));
The results are indeed showing up after a randomized maximum time period, as expected.
Upon revisiting the documentation, it seems that what I have implemented should not actually be working as intended.
https://i.sstatic.net/u5QHI.png
It is important to note that the variable d
holds the type Observable <{}[]>
, making it an observable of an array.
However, according to the documentation:
sources :SubscribableOrPromise Any number of Observables provided either as an array or as arguments passed directly to the operator.
In my case, I am not passing an array directly. As a result, using forkJoin(...d)
will not yield the desired outcome.
Question:
Is my usage of forkJoin
incorrect? How does this conflict with the documented behavior?