Allow other things to talk to the worker
This commit is contained in:
parent
b5f35e1f95
commit
ee9aeb8c3c
@ -42,7 +42,7 @@ export function WorkerPortal(context, worker, serialize) {
|
|||||||
_worker.postMessage(_serialize(type, destination, id, params));
|
_worker.postMessage(_serialize(type, destination, id, params));
|
||||||
}
|
}
|
||||||
|
|
||||||
_worker.onmessage = function dispatcher(evt) {
|
function dispatcher(evt) {
|
||||||
let data;
|
let data;
|
||||||
try {
|
try {
|
||||||
data = JSON.parse(evt.data);
|
data = JSON.parse(evt.data);
|
||||||
@ -80,7 +80,8 @@ export function WorkerPortal(context, worker, serialize) {
|
|||||||
} else {
|
} else {
|
||||||
_resolve(thennable);
|
_resolve(thennable);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
function injectionPointFactory(fnId, fnName, callbackFactory) {
|
function injectionPointFactory(fnId, fnName, callbackFactory) {
|
||||||
return () =>
|
return () =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
@ -102,6 +103,8 @@ export function WorkerPortal(context, worker, serialize) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_worker.addEventListener('message', dispatcher);
|
||||||
|
|
||||||
return isWorker()
|
return isWorker()
|
||||||
? new Promise(resolve => {
|
? new Promise(resolve => {
|
||||||
contextIndex.splice(0, 0, '__init');
|
contextIndex.splice(0, 0, '__init');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user