Bug 1580485 - Start search worker on lazily. r=jlast

Took care to only call .task once. Maybe it would be nice to move this functionality inside `WorkerDispatcher`?

Differential Revision: https://phabricator.services.mozilla.com/D45534

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Sorin Davidoi 2019-09-12 18:41:51 +00:00
Родитель 92ce0226c3
Коммит 4bb2a97856
1 изменённых файлов: 30 добавлений и 5 удалений

Просмотреть файл

@ -7,9 +7,34 @@
import { workerUtils } from "devtools-utils";
const { WorkerDispatcher } = workerUtils;
const dispatcher = new WorkerDispatcher();
export const start = dispatcher.start.bind(dispatcher);
export const stop = dispatcher.stop.bind(dispatcher);
let startArgs;
let dispatcher;
export const getMatches = dispatcher.task("getMatches");
export const findSourceMatches = dispatcher.task("findSourceMatches");
function getDispatcher() {
if (!dispatcher) {
dispatcher = new WorkerDispatcher();
dispatcher.start(...startArgs);
}
return dispatcher;
}
export const start = (...args: any[]) => {
startArgs = args;
};
export const stop = () => {
if (dispatcher) {
dispatcher.stop();
dispatcher = null;
startArgs = null;
}
};
export const getMatches = (...args: any[]) => {
return getDispatcher().invoke("getMatches", ...args);
};
export const findSourceMatches = (...args: any[]) => {
return getDispatcher().invoke("findSourceMatches", ...args);
};