зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
7141b73975
Коммит
c9a76c17f4
|
@ -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) => {
|
||||
startArgs = args;
|
||||
};
|
||||
|
||||
export const stop = () => {
|
||||
if (dispatcher) {
|
||||
dispatcher.stop();
|
||||
dispatcher = null;
|
||||
startArgs = null;
|
||||
}
|
||||
};
|
||||
|
||||
export const getMatches = (...args) => {
|
||||
return getDispatcher().invoke("getMatches", ...args);
|
||||
};
|
||||
|
||||
export const findSourceMatches = (...args) => {
|
||||
return getDispatcher().invoke("findSourceMatches", ...args);
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче