mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-22 16:18:08 +02:00
Merge pull request #11573 from Snuffleupagus/api-cleanup-returns
[api-minor] Change `PDFDocumentProxy.cleanup`/`PDFPageProxy.cleanup` to return data
This commit is contained in:
commit
7948faf675
2 changed files with 105 additions and 6 deletions
|
@ -758,10 +758,16 @@ class PDFDocumentProxy {
|
|||
}
|
||||
|
||||
/**
|
||||
* Cleans up resources allocated by the document, e.g. created `@font-face`.
|
||||
* Cleans up resources allocated by the document, on both the main- and
|
||||
* worker-threads.
|
||||
*
|
||||
* NOTE: Do not, under any circumstances, call this method when rendering is
|
||||
* currently ongoing since that may lead to rendering errors.
|
||||
*
|
||||
* @returns {Promise} A promise that is resolved when clean-up has finished.
|
||||
*/
|
||||
cleanup() {
|
||||
this._transport.startCleanup();
|
||||
return this._transport.startCleanup();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1269,10 +1275,11 @@ class PDFPageProxy {
|
|||
* Cleans up resources allocated by the page.
|
||||
* @param {boolean} [resetStats] - Reset page stats, if enabled.
|
||||
* The default value is `false`.
|
||||
* @returns {boolean} Indicating if clean-up was successfully run.
|
||||
*/
|
||||
cleanup(resetStats = false) {
|
||||
this.pendingCleanup = true;
|
||||
this._tryCleanup(resetStats);
|
||||
return this._tryCleanup(resetStats);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1290,7 +1297,7 @@ class PDFPageProxy {
|
|||
);
|
||||
})
|
||||
) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
Object.keys(this.intentStates).forEach(intent => {
|
||||
|
@ -1302,6 +1309,7 @@ class PDFPageProxy {
|
|||
this._stats = new StatTimer();
|
||||
}
|
||||
this.pendingCleanup = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2555,11 +2563,17 @@ class WorkerTransport {
|
|||
}
|
||||
|
||||
startCleanup() {
|
||||
this.messageHandler.sendWithPromise("Cleanup", null).then(() => {
|
||||
return this.messageHandler.sendWithPromise("Cleanup", null).then(() => {
|
||||
for (let i = 0, ii = this.pageCache.length; i < ii; i++) {
|
||||
const page = this.pageCache[i];
|
||||
if (page) {
|
||||
page.cleanup();
|
||||
const cleanupSuccessful = page.cleanup();
|
||||
|
||||
if (!cleanupSuccessful) {
|
||||
throw new Error(
|
||||
`startCleanup: Page ${i + 1} is currently rendering.`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.commonObjs.clear();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue