worker.js: do not run wasm_bindgen multiple times

seems like this thing can fail occassionally. just don't run bindgen
all the time.
This commit is contained in:
Peter Cai 2020-04-08 21:29:20 +08:00
parent fe22944cb4
commit e562a8d7e4
No known key found for this signature in database
GPG Key ID: 71F5FB4E4F3FD54F
1 changed files with 5 additions and 1 deletions

View File

@ -1,4 +1,5 @@
const { handle_request_rs } = wasm_bindgen;
var gen = false;
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
@ -9,6 +10,9 @@ addEventListener('fetch', event => {
* @param {Request} request
*/
async function handleRequest(request) {
if (!gen) {
await wasm_bindgen(wasm);
return await handle_request_rs(request);
gen = true;
}
return await handle_request_rs(request);
}