-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathworkers.js
More file actions
31 lines (27 loc) · 992 Bytes
/
workers.js
File metadata and controls
31 lines (27 loc) · 992 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
25
26
27
28
29
30
31
import withResolvers from '@webreflection/utils/with-resolvers';
// REQUIRES INTEGRATION TEST
/* c8 ignore start */
export const workers = new Proxy(new Map, {
get(map, name) {
if (!map.has(name))
map.set(name, withResolvers());
return map.get(name);
},
});
// filter out forever pending Promises in Pyodide
// @issue https://github.com/pyscript/pyscript/issues/2106
const ignore = new Set(['__dict__', 'constructor', 'get', 'has', 'includes', 'next', 'set', 'then']);
const exportHandler = {
get: (target, prop) => {
const method = target[prop];
return prop === '__export__' ? method() : method;
}
};
export const workersHandler = new Proxy(Object.freeze({}), {
// guard against forever pending Promises in Pyodide
// @issue https://github.com/pyscript/pyscript/issues/2106
get: (_, name) => (typeof name === 'string' && !ignore.has(name)) ?
workers[name].promise.then(w => new Proxy(w.sync, exportHandler)) :
void 0,
});
/* c8 ignore stop */