Merge pull request #42 from syumai/update-worker-mjs

update worker.mjs
This commit is contained in:
syumai 2023-04-29 18:32:12 +09:00 committed by GitHub
commit 4a1d49c53e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 60 additions and 228 deletions

24
examples/assets/shim.mjs Normal file
View File

@ -0,0 +1,24 @@
import "./polyfill_performance.js";
import "./wasm_exec.js";
const go = new Go();
let mod;
export function init(m) {
mod = m;
}
async function run() {
const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});
const instance = new WebAssembly.Instance(mod, go.importObject);
go.run(instance);
await readyPromise;
}
export async function fetch(req, env, ctx) {
await run();
return handleRequest(req, { env, ctx });
}

View File

@ -1,22 +1,6 @@
import "../assets/polyfill_performance.js";
import "../assets/wasm_exec.js";
import * as imports from "../assets/shim.mjs";
import mod from "./dist/app.wasm";
const go = new Go();
imports.init(mod);
const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});
const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
go.run(instance);
return instance;
});
export default {
async fetch(req, env, ctx) {
await load;
await readyPromise;
return handleRequest(req, { env, ctx });
}
}
export default { fetch: imports.fetch }

View File

@ -1,22 +1,6 @@
import "../assets/polyfill_performance.js";
import "../assets/wasm_exec.js";
import * as imports from "../assets/shim.mjs";
import mod from "./dist/app.wasm";
const go = new Go();
imports.init(mod);
const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});
const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
go.run(instance);
return instance;
});
export default {
async fetch(req, env, ctx) {
await load;
await readyPromise;
return handleRequest(req, { env, ctx });
}
}
export default { fetch: imports.fetch }

View File

@ -1,22 +1,6 @@
import "../assets/polyfill_performance.js";
import "../assets/wasm_exec.js";
import * as imports from "../assets/shim.mjs";
import mod from "./dist/app.wasm";
const go = new Go();
imports.init(mod);
const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});
const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
go.run(instance);
return instance;
});
export default {
async fetch(req, env, ctx) {
await load;
await readyPromise;
return handleRequest(req, { env, ctx });
}
}
export default { fetch: imports.fetch }

View File

@ -1,25 +1,9 @@
import "../assets/polyfill_performance.js";
import "../assets/wasm_exec.js";
import * as imports from "../assets/shim.mjs";
import mod from "./dist/app.wasm";
const go = new Go();
imports.init(mod);
const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});
const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
go.run(instance);
return instance;
});
export default {
async fetch(req, env, ctx) {
await load;
await readyPromise;
return handleRequest(req, { env, ctx });
}
}
export default { fetch: imports.fetch }
// Durable Object

View File

@ -1,22 +1,6 @@
import "../assets/polyfill_performance.js";
import "../assets/wasm_exec.js";
import * as imports from "../assets/shim.mjs";
import mod from "./dist/app.wasm";
const go = new Go();
imports.init(mod);
const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});
const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
go.run(instance);
return instance;
});
export default {
async fetch(req, env, ctx) {
await load;
await readyPromise;
return handleRequest(req, { env, ctx });
}
}
export default { fetch: imports.fetch }

View File

@ -1,22 +1,6 @@
import "../assets/polyfill_performance.js";
import "../assets/wasm_exec.js";
import * as imports from "../assets/shim.mjs";
import mod from "./dist/app.wasm";
const go = new Go();
imports.init(mod);
const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});
const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
go.run(instance);
return instance;
});
export default {
async fetch(req, env, ctx) {
await load;
await readyPromise;
return handleRequest(req, { env, ctx });
}
}
export default { fetch: imports.fetch }

View File

@ -1,22 +1,6 @@
import "../assets/polyfill_performance.js";
import "../assets/wasm_exec.js";
import * as imports from "../assets/shim.mjs";
import mod from "./dist/app.wasm";
const go = new Go();
imports.init(mod);
const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});
const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
go.run(instance);
return instance;
});
export default {
async fetch(req, env, ctx) {
await load;
await readyPromise;
return handleRequest(req, { env, ctx });
}
}
export default { fetch: imports.fetch }

View File

@ -1,22 +1,6 @@
import "../assets/polyfill_performance.js";
import "../assets/wasm_exec.js";
import * as imports from "../assets/shim.mjs";
import mod from "./dist/app.wasm";
const go = new Go();
imports.init(mod);
const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});
const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
go.run(instance);
return instance;
});
export default {
async fetch(req, env, ctx) {
await load;
await readyPromise;
return handleRequest(req, { env, ctx });
}
}
export default { fetch: imports.fetch }

View File

@ -1,22 +1,6 @@
import "../assets/polyfill_performance.js";
import "../assets/wasm_exec.js";
import * as imports from "../assets/shim.mjs";
import mod from "./dist/app.wasm";
const go = new Go();
imports.init(mod);
const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});
const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
go.run(instance);
return instance;
});
export default {
async fetch(req, env, ctx) {
await load;
await readyPromise;
return handleRequest(req, { env, ctx });
}
}
export default { fetch: imports.fetch }

View File

@ -1,22 +1,6 @@
import "../assets/polyfill_performance.js";
import "../assets/wasm_exec.js";
import * as imports from "../assets/shim.mjs";
import mod from "./dist/app.wasm";
const go = new Go();
imports.init(mod);
const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});
const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
go.run(instance);
return instance;
});
export default {
async fetch(req, env, ctx) {
await load;
await readyPromise;
return handleRequest(req, { env, ctx });
}
}
export default { fetch: imports.fetch }

View File

@ -1,22 +1,6 @@
import "../assets/polyfill_performance.js";
import "../assets/wasm_exec.js";
import * as imports from "../assets/shim.mjs";
import mod from "./dist/app.wasm";
const go = new Go();
imports.init(mod);
const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});
const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
go.run(instance);
return instance;
});
export default {
async fetch(req, env, ctx) {
await load;
await readyPromise;
return handleRequest(req, { env, ctx });
}
}
export default { fetch: imports.fetch }

View File

@ -1,22 +1,6 @@
import "../assets/polyfill_performance.js";
import "../assets/wasm_exec.js";
import * as imports from "../assets/shim.mjs";
import mod from "./dist/app.wasm";
const go = new Go();
imports.init(mod);
const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});
const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
go.run(instance);
return instance;
});
export default {
async fetch(req, env, ctx) {
await load;
await readyPromise;
return handleRequest(req, { env, ctx });
}
}
export default { fetch: imports.fetch }