andywer / threads.js

🧵 Make web workers & worker threads as simple as a function call.
https://threads.js.org/
MIT License
3.04k stars 161 forks source link

Promised Observable #475

Open balbatross opened 1 year ago

balbatross commented 1 year ago

Kia Ora,

We're trying to run an async function that returns an observable, because of the structure of the resultType the library tries to serialize our Observable function leading to a DataCloneError.

Would a promised-observable resultType cause confusion? Happy to put the time in for a PR.

linonetwo commented 1 year ago

Try iife, like what we do in useEffect


function runLLama(
  options: { conversationID: string; modelPath: string; openDebugger?: boolean; prompt: string },
): Observable<ILanguageModelWorkerResponse> {

  return new Observable<ILanguageModelWorkerResponse>((subscriber) => {
    void (async function runLLamaObservableIIFE() {
      await xxx
    })();
  });
}