-
Notifications
You must be signed in to change notification settings - Fork 4
Include SharedWorker in WebWorkerAPI #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
2ba00a9
bba4378
5e68e66
b43d65d
5d002a7
ea3435c
9ba8ac1
b3e2183
047274d
d3e3f12
1800c2f
e427052
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
.astro | ||
dist/ | ||
tmp/ | ||
docs/public/llm.txt | ||
docs/public/llm.txt | ||
*~ | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
open ChannelMessagingAPI | ||
open WebWorkersAPI | ||
|
||
include EventTarget.Impl({ | ||
type t = sharedWorker | ||
}) | ||
|
||
/** | ||
`make(string)` | ||
|
||
The SharedWorker() constructor creates a SharedWorker object that executes the | ||
script at the specified URL. This script must obey the same-origin policy. | ||
|
||
```res | ||
let shared: sharedWorker = SharedWorker.make("sharedworker.js") | ||
``` | ||
|
||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker/) | ||
*/ | ||
@new | ||
external make: string => sharedWorker = "SharedWorker" | ||
|
||
/** | ||
`make_withName(string, string)` | ||
|
||
The SharedWorker() constructor creates a SharedWorker object that executes the | ||
script at the specified URL. This script must obey the same-origin policy. | ||
|
||
```res | ||
let shared: sharedWorker = SharedWorker.make("sharedworker.js", "name") | ||
``` | ||
|
||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker/) | ||
*/ | ||
@new | ||
external make_withName: (string, string) => sharedWorker = "SharedWorker" | ||
switch-to-gitlab marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
`make_withOptions(string, workerOptions)` | ||
|
||
The SharedWorker() constructor creates a SharedWorker object that executes the | ||
script at the specified URL. This script must obey the same-origin policy. | ||
|
||
```res | ||
let shared3: sharedWorker = SharedWorker.make_withOptions("sharedworker.js", { | ||
name: "workerName", | ||
type_: Module | ||
}) | ||
``` | ||
|
||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker/) | ||
*/ | ||
@new | ||
external make_withOptions: (string, workerOptions) => sharedWorker = "SharedWorker" | ||
|
||
/** | ||
`port(sharedWorker)` | ||
|
||
The port property of the SharedWorker interface returns a MessagePort object | ||
used to communicate and control the shared worker. | ||
|
||
```res | ||
let port: WebAPI.ChannelMessagingAPI.messagePort = SharedWorker.port(myWorker) | ||
``` | ||
|
||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker/port) | ||
*/ | ||
@get | ||
external port: sharedWorker => messagePort = "port" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
open WebWorkersAPI | ||
|
||
module Impl = ( | ||
T: { | ||
type t | ||
}, | ||
) => { | ||
include WorkerGlobalScope.Impl({ | ||
type t = T.t | ||
}) | ||
|
||
/** | ||
`close(sharedWorkerGlobalScope)` | ||
|
||
The close() method of the SharedWorkerGlobalScope interface discards any tasks | ||
queued in the SharedWorkerGlobalScope's event loop, effectively closing this | ||
particular scope. | ||
|
||
```res | ||
self -> SharedWorkerGlobalScope.close | ||
``` | ||
|
||
[Read more on MDN](https://developer.mozilla.org/en-US/docs/Web/API/SharedWorkerGlobalScope/close) | ||
*/ | ||
@send | ||
external close: T.t => unit = "close" | ||
} | ||
|
||
include Impl({ | ||
type t = sharedWorkerGlobalScope | ||
}) | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
open WebAPI.WebWorkersAPI | ||
|
||
external getSelf: () => sharedWorkerGlobalScope = "self" | ||
|
||
let self = getSelf() | ||
|
||
self -> SharedWorkerGlobalScope.close |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
open WebAPI.WebWorkersAPI | ||
|
||
let shared1: sharedWorker = SharedWorker.make("sharedworker.js") | ||
|
||
let shared2: sharedWorker = SharedWorker.make_withName("sharedworker.js", "name") | ||
|
||
let shared3: sharedWorker = SharedWorker.make_withOptions("sharedworker.js", { | ||
name: "workerName", | ||
type_: Module | ||
}) | ||
|
||
let port: WebAPI.ChannelMessagingAPI.messagePort = SharedWorker.port(shared1) | ||
|
||
external getSelf: () => sharedWorkerGlobalScope = "self" | ||
|
||
let self = getSelf() | ||
|
||
self -> SharedWorkerGlobalScope.close |
Uh oh!
There was an error while loading. Please reload this page.