coty
coty
DDeno
Created by coty on 6/27/2024 in #help
How to detect if executing on main thread vs worker
function main() {
// create worker from this same file
const worker = new Worker(import.meta.resolve("./mod.ts"), {
name: "hello-worker",
type: "module",
});
worker.onmessage = (e: MessageEvent<{ message: string }>) => {
console.log(e.data.message);
};
worker.postMessage({
message: "hello",
});
}

if (import.meta.main) {
if (self.window) {
main();
} else {
const worker = self as unknown as Worker & { name?: string };
worker.onmessage = (e: MessageEvent<{ message: string }>) => {
worker.postMessage({
message: `${e.data.message} from ${worker.name}`,
});
self.close();
};
}
}
function main() {
// create worker from this same file
const worker = new Worker(import.meta.resolve("./mod.ts"), {
name: "hello-worker",
type: "module",
});
worker.onmessage = (e: MessageEvent<{ message: string }>) => {
console.log(e.data.message);
};
worker.postMessage({
message: "hello",
});
}

if (import.meta.main) {
if (self.window) {
main();
} else {
const worker = self as unknown as Worker & { name?: string };
worker.onmessage = (e: MessageEvent<{ message: string }>) => {
worker.postMessage({
message: `${e.data.message} from ${worker.name}`,
});
self.close();
};
}
}
I put everything in one file to make it easier to show, but is checking for self.window the preferred way? or is there some value in Deno context? Bonus question, how can you properly type self when in a worker? That type casting is neither pretty nor accurate
4 replies
DDeno
Created by coty on 5/21/2024 in #help
Debug deno deploy failures ISOLATE_INTERNAL_FAILURE
how can you debug deno deploy failures?
cotyhamilton dev/no-build (main)
➜ deployctl deploy --project=no-build --entrypoint=mod.ts
ℹ Using config file '/Users/cotyhamilton/dev/no-build/deno.json'
✔ Deploying to project no-build.
✔ Entrypoint: /Users/cotyhamilton/dev/no-build/mod.ts
ℹ Uploading all files from the current dir (/Users/cotyhamilton/dev/no-build)
✔ Found 37 assets.
✔ No new assets to upload.
✖ Deployment failed.
error: The deployment failed: ISOLATE_INTERNAL_FAILURE

cotyhamilton dev/no-build (main)
➜ deployctl logs --project=no-build
ℹ Using config file '/Users/cotyhamilton/dev/no-build/deno.json'
✔ Project: no-build
2024-05-21T04:35:51.362199787Z gcp-us-east4 isolate start time: 16.20 ms
2024-05-21T04:35:54.596194223Z gcp-us-east4 isolate start time: 16.19 ms
2024-05-21T04:35:57.966894225Z gcp-us-east4 isolate start time: 27.15 ms
2024-05-21T04:36:01.619310600Z gcp-us-east4 isolate start time: 21.97 ms
2024-05-21T04:36:05.593898029Z gcp-us-east4 isolate start time: 27.28 ms
cotyhamilton dev/no-build (main)
➜ deployctl deploy --project=no-build --entrypoint=mod.ts
ℹ Using config file '/Users/cotyhamilton/dev/no-build/deno.json'
✔ Deploying to project no-build.
✔ Entrypoint: /Users/cotyhamilton/dev/no-build/mod.ts
ℹ Uploading all files from the current dir (/Users/cotyhamilton/dev/no-build)
✔ Found 37 assets.
✔ No new assets to upload.
✖ Deployment failed.
error: The deployment failed: ISOLATE_INTERNAL_FAILURE

cotyhamilton dev/no-build (main)
➜ deployctl logs --project=no-build
ℹ Using config file '/Users/cotyhamilton/dev/no-build/deno.json'
✔ Project: no-build
2024-05-21T04:35:51.362199787Z gcp-us-east4 isolate start time: 16.20 ms
2024-05-21T04:35:54.596194223Z gcp-us-east4 isolate start time: 16.19 ms
2024-05-21T04:35:57.966894225Z gcp-us-east4 isolate start time: 27.15 ms
2024-05-21T04:36:01.619310600Z gcp-us-east4 isolate start time: 21.97 ms
2024-05-21T04:36:05.593898029Z gcp-us-east4 isolate start time: 27.28 ms
4 replies