Reputation: 159
Deno: v1.19.0
Deno Doc Ref: Deno Manual, chapt. 3.6 Workers
MDN Web Docs: Javascript : Using Web Workers
According to the above Deno docs the Web Workers API is supported. The types derived from the abstract class for this API are Worker, SharedWorker and ServiceWorker as can be seen in the MDN Web Docs link. The Dedicated Worker seems to be implemented.
With Dedicated Workers all seems to work fine.
workerList[i] = new Worker(new URL(authJson.workers[i].projectFile, import.meta.url).href, { type: "module", deno: { namespace: true, }});
With Shared Workers an error occurs: ReferenceError: SharedWorker is not defined
workerList[i] = new SharedWorker(new URL(authJson.workers[i].projectFile, import.meta.url).href, { type: "module", deno: { namespace: true, }});
I have seen in the past that Deno says somthing is supported without saying that it is only partially supported. Example passing Shared Memory Arrays with postMessage, should only be working recently with 1.9.0.
Could it be that Deno does not support the Web Worker API and just has a Worker implementation and no SharedWorker, or is there something to know about using the above SharedWorker that isn't in the Deno documentation?
If the answer would be that Shared Workers are not supported yet, then please where did you find such information, because I have read the complete Deno Worker API and while it refers to the MDN Web Docs it does, unless I am wrong, say nowhere in their docs that they don't fully support the API they are refering to as supported by Deno.
PS: Before someone asks...why do you need ... :)
SharedWorkers: Represents a specific kind of worker that can be accessed from several browsing contexts, being several windows, iframes or even workers.
Hence Shared Workers can exchange messages with other workers, not only a single parent such as the main thread that created them. They have a MessagePort object.
Upvotes: 1
Views: 1151
Reputation: 159
SharedWorkers from the Worker API are not implemented in Deno, only Dedidcated Workers are.
According to this issue 7728 discussion SharedWorkers require structured cloning to be available.
According to this discussion structured cloning is being worked on since a while.
Passing SMAs between threads with postMessage is only just available since Deno 1.9.0. Possibly passing MessagePort objects (which would be needed in SharedWorkers) might be based on that ability (speculation).
The SharedWorker type is however already declared here in the Deno code.
If anyone can add more information as to the availability of SharedWorkers, pls share. They are extremely useful in Multi-threading programming, modularity and smooth processing.
Upvotes: 2