mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-06-23 16:35:47 +02:00
Reduce duplication when invoking finishWorkerTask
By utilizing `Promise.prototype.finally()` more it's possible to avoid a bit of duplication when invoking `finishWorkerTask`.
This commit is contained in:
parent
e75a7cfd62
commit
c88f0bba04
@ -579,16 +579,9 @@ class WorkerMessageHandler {
|
|||||||
const task = new WorkerTask(`GetAnnotations: page ${pageIndex}`);
|
const task = new WorkerTask(`GetAnnotations: page ${pageIndex}`);
|
||||||
startWorkerTask(task);
|
startWorkerTask(task);
|
||||||
|
|
||||||
return page.getAnnotationsData(handler, task, intent).then(
|
return page.getAnnotationsData(handler, task, intent).finally(() => {
|
||||||
data => {
|
finishWorkerTask(task);
|
||||||
finishWorkerTask(task);
|
});
|
||||||
return data;
|
|
||||||
},
|
|
||||||
reason => {
|
|
||||||
finishWorkerTask(task);
|
|
||||||
throw reason;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -773,7 +766,7 @@ class WorkerMessageHandler {
|
|||||||
imagePromises,
|
imagePromises,
|
||||||
changes
|
changes
|
||||||
)
|
)
|
||||||
.finally(function () {
|
.finally(() => {
|
||||||
finishWorkerTask(task);
|
finishWorkerTask(task);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@ -818,7 +811,7 @@ class WorkerMessageHandler {
|
|||||||
|
|
||||||
return page
|
return page
|
||||||
.save(handler, task, annotationStorage, changes)
|
.save(handler, task, annotationStorage, changes)
|
||||||
.finally(function () {
|
.finally(() => {
|
||||||
finishWorkerTask(task);
|
finishWorkerTask(task);
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
@ -928,9 +921,7 @@ class WorkerMessageHandler {
|
|||||||
pageIndex,
|
pageIndex,
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
function (operatorListInfo) {
|
operatorListInfo => {
|
||||||
finishWorkerTask(task);
|
|
||||||
|
|
||||||
if (start) {
|
if (start) {
|
||||||
info(
|
info(
|
||||||
`page=${pageIndex + 1} - getOperatorList: time=` +
|
`page=${pageIndex + 1} - getOperatorList: time=` +
|
||||||
@ -939,8 +930,7 @@ class WorkerMessageHandler {
|
|||||||
}
|
}
|
||||||
sink.close();
|
sink.close();
|
||||||
},
|
},
|
||||||
function (reason) {
|
reason => {
|
||||||
finishWorkerTask(task);
|
|
||||||
if (task.terminated) {
|
if (task.terminated) {
|
||||||
return; // ignoring errors from the terminated thread
|
return; // ignoring errors from the terminated thread
|
||||||
}
|
}
|
||||||
@ -949,7 +939,10 @@ class WorkerMessageHandler {
|
|||||||
// TODO: Should `reason` be re-thrown here (currently that casues
|
// TODO: Should `reason` be re-thrown here (currently that casues
|
||||||
// "Uncaught exception: ..." messages in the console)?
|
// "Uncaught exception: ..." messages in the console)?
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
|
.finally(() => {
|
||||||
|
finishWorkerTask(task);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -973,9 +966,7 @@ class WorkerMessageHandler {
|
|||||||
disableNormalization,
|
disableNormalization,
|
||||||
})
|
})
|
||||||
.then(
|
.then(
|
||||||
function () {
|
() => {
|
||||||
finishWorkerTask(task);
|
|
||||||
|
|
||||||
if (start) {
|
if (start) {
|
||||||
info(
|
info(
|
||||||
`page=${pageIndex + 1} - getTextContent: time=` +
|
`page=${pageIndex + 1} - getTextContent: time=` +
|
||||||
@ -984,8 +975,7 @@ class WorkerMessageHandler {
|
|||||||
}
|
}
|
||||||
sink.close();
|
sink.close();
|
||||||
},
|
},
|
||||||
function (reason) {
|
reason => {
|
||||||
finishWorkerTask(task);
|
|
||||||
if (task.terminated) {
|
if (task.terminated) {
|
||||||
return; // ignoring errors from the terminated thread
|
return; // ignoring errors from the terminated thread
|
||||||
}
|
}
|
||||||
@ -994,7 +984,10 @@ class WorkerMessageHandler {
|
|||||||
// TODO: Should `reason` be re-thrown here (currently that casues
|
// TODO: Should `reason` be re-thrown here (currently that casues
|
||||||
// "Uncaught exception: ..." messages in the console)?
|
// "Uncaught exception: ..." messages in the console)?
|
||||||
}
|
}
|
||||||
);
|
)
|
||||||
|
.finally(() => {
|
||||||
|
finishWorkerTask(task);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user