Skip to content

Commit

Permalink
Merge pull request #12004 from Snuffleupagus/worker-class
Browse files Browse the repository at this point in the history
Convert the code in `src/core/worker.js` to use ES6 classes
  • Loading branch information
timvandermeij authored Jun 17, 2020
2 parents 6bb64da + fb9b574 commit 3067917
Showing 1 changed file with 27 additions and 30 deletions.
57 changes: 27 additions & 30 deletions src/core/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,34 @@ import { MessageHandler } from "../shared/message_handler.js";
import { PDFWorkerStream } from "./worker_stream.js";
import { XRefParseException } from "./core_utils.js";

var WorkerTask = (function WorkerTaskClosure() {
// eslint-disable-next-line no-shadow
function WorkerTask(name) {
class WorkerTask {
constructor(name) {
this.name = name;
this.terminated = false;
this._capability = createPromiseCapability();
}

WorkerTask.prototype = {
get finished() {
return this._capability.promise;
},

finish() {
this._capability.resolve();
},
get finished() {
return this._capability.promise;
}

terminate() {
this.terminated = true;
},
finish() {
this._capability.resolve();
}

ensureNotTerminated() {
if (this.terminated) {
throw new Error("Worker task was terminated");
}
},
};
terminate() {
this.terminated = true;
}

return WorkerTask;
})();
ensureNotTerminated() {
if (this.terminated) {
throw new Error("Worker task was terminated");
}
}
}

var WorkerMessageHandler = {
setup(handler, port) {
class WorkerMessageHandler {
static setup(handler, port) {
var testMessageProcessed = false;
handler.on("test", function wphSetupTest(data) {
if (testMessageProcessed) {
Expand All @@ -96,8 +91,9 @@ var WorkerMessageHandler = {
handler.on("GetDocRequest", function wphSetupDoc(data) {
return WorkerMessageHandler.createDocumentHandler(data, port);
});
},
createDocumentHandler(docParams, port) {
}

static createDocumentHandler(docParams, port) {
// This context is actually holds references on pdfManager and handler,
// until the latter is destroyed.
var pdfManager;
Expand Down Expand Up @@ -662,13 +658,14 @@ var WorkerMessageHandler = {
docParams = null; // we don't need docParams anymore -- saving memory.
});
return workerHandlerName;
},
initializeFromPort(port) {
}

static initializeFromPort(port) {
var handler = new MessageHandler("worker", "main", port);
WorkerMessageHandler.setup(handler, port);
handler.send("ready", null);
},
};
}
}

function isMessagePort(maybePort) {
return (
Expand Down

0 comments on commit 3067917

Please sign in to comment.