Skip to content

Commit

Permalink
Merge pull request #17 from syumai/wait-for-ready
Browse files Browse the repository at this point in the history
wait for ready to setup Go program
  • Loading branch information
syumai authored Nov 19, 2022
2 parents 8794617 + 1f6f230 commit 0e499ad
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/basic-auth-proxy/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
return instance;
});

const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});

async function processRequest(event) {
const req = event.request;
await load;
await readyPromise;
return handleRequest(req);
}

Expand Down
5 changes: 5 additions & 0 deletions examples/env/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
return instance;
});

const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});

async function processRequest(event) {
const req = event.request;
await load;
await readyPromise;
return handleRequest(req);
}

Expand Down
5 changes: 5 additions & 0 deletions examples/hello/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
return instance;
});

const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});

async function processRequest(event) {
const req = event.request;
await load;
await readyPromise;
return handleRequest(req);
}

Expand Down
5 changes: 5 additions & 0 deletions examples/kv-counter/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
return instance;
});

const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});

async function processRequest(event) {
const req = event.request;
await load;
await readyPromise;
return handleRequest(req);
}

Expand Down
5 changes: 5 additions & 0 deletions examples/r2-image-server/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
return instance;
});

const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});

async function processRequest(event) {
const req = event.request;
await load;
await readyPromise;
return handleRequest(req);
}

Expand Down
5 changes: 5 additions & 0 deletions examples/r2-image-viewer/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
return instance;
});

const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});

async function processRequest(event) {
const req = event.request;
await load;
await readyPromise;
return handleRequest(req);
}

Expand Down
5 changes: 5 additions & 0 deletions examples/simple-json-server/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@ const load = WebAssembly.instantiate(mod, go.importObject).then((instance) => {
return instance;
});

const readyPromise = new Promise((resolve) => {
globalThis.ready = resolve;
});

async function processRequest(event) {
const req = event.request;
await load;
await readyPromise;
return handleRequest(req);
}

Expand Down
1 change: 1 addition & 0 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ func Serve(handler http.Handler) {
handler = http.DefaultServeMux
}
httpHandler = handler
jsutil.Global.Call("ready")
select {}
}

0 comments on commit 0e499ad

Please sign in to comment.