You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
there's no dedicated way to post arbitrary messages (or events) to the main thread and receive them.
Currently, you could pass a stream to the thread (see transfer-streams.worker.ts) and write the progress to it periodically.
Another option is to query the worker state (via a new method in your worker). This will probably work just fine (note: I did not try this :) ) if the work done in the thread isn't blocking.
Other than that, it maybe makes sense to add a new WorkerMessageType for progress or even arbitrary events.
I suppose another (not to dissimilar, but maybe more general) way to add this functionality, would be through observable promises (you know... pub-sub). threads.js does have those, but I chose not to add them to threads-es to begin with.
And there was something else on my mind for a while.... there's threads-esm, which allows bidirectional communication (the worker can call methods on the main thread).
Generally, I would prefer to only add functionality if really needed, and the most versatile at that. Which would probably be observable promises.
Please let me know if the methods in the prev comment would do the trick for you (I know safari has issues with streams not being transferable - altho maybe they fixed this by now).
Hi @852Kerfunkle, WritableStream worked perfectly for my use case, thanks for pointing it out. Maybe an example in the README might help future users, or maybe just pin this issue.
Is there a method to post progress messages back to the main thread?
I do not think I can use
postMessage
, maybe there is a way through events?The text was updated successfully, but these errors were encountered: