const fetchData = thread(require('worker-loader!./fetch-data'))
// or
const fetchData = thread(async url => {
return (await fetch(url)).json()
})
// fetchData :: ThenableObservable
const data = await fetchData('/api/me')- A "thenable observable" is returned, since we don't know if the function is sync, async or returns an observable before running it
- If the function is sync or async then the "thenable observable" resolves to the returned value and emits a single
nextand acompleteon the observable interface - If the function returns an observable then the "thenable observable" resolves without a value on
completeand passes-through thenexts
- Need to provide some polyfill for node (working similar to https://github.com/boblauer/mock-require)
At least thread(require('worker-loader!...')) will result in a new worker for every thread() call which might be a performance problem. Maybe something like https://github.com/eoin/entry-loader might be an alternative.
Another solution might be having a `pooled-worker-loader` that works on top of virtualized web workers: There is a pool of *CPU core count* web workers which run any random number of web-worker-like virtual workers.