-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathworker.js
More file actions
24 lines (20 loc) · 570 Bytes
/
worker.js
File metadata and controls
24 lines (20 loc) · 570 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
const Module = require('./dist/camaro')
let cachedInstance
function callWasmBinding(methodName, ...args) {
if (!cachedInstance) throw new Error('camaro is not initialized yet.')
return cachedInstance[methodName](...args)
}
const ready = new Promise((resolve, reject) => {
if (!cachedInstance) {
Module().then((instance) => {
cachedInstance = instance
resolve()
})
} else {
resolve()
}
})
module.exports = async ({fn, args}) => {
await ready
return callWasmBinding(fn, ...args)
}