Closes all promises/streams when handler is destroyed.
This commit is contained in:
parent
25806d17f4
commit
71b0e4e818
@ -14,10 +14,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import {
|
import {
|
||||||
arrayByteLength, arraysToBytes, assert, createPromiseCapability, info,
|
AbortException, arrayByteLength, arraysToBytes, assert,
|
||||||
InvalidPDFException, isNodeJS, MessageHandler, MissingPDFException,
|
createPromiseCapability, info, InvalidPDFException, isNodeJS, MessageHandler,
|
||||||
PasswordException, setVerbosityLevel, UnexpectedResponseException,
|
MissingPDFException, PasswordException, setVerbosityLevel,
|
||||||
UnknownErrorException, UNSUPPORTED_FEATURES, warn, XRefParseException
|
UnexpectedResponseException, UnknownErrorException, UNSUPPORTED_FEATURES,
|
||||||
|
warn, XRefParseException
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
|
import { LocalPdfManager, NetworkPdfManager } from './pdf_manager';
|
||||||
import { Ref } from './primitives';
|
import { Ref } from './primitives';
|
||||||
@ -841,7 +842,7 @@ var WorkerMessageHandler = {
|
|||||||
return Promise.all(waitOn).then(function () {
|
return Promise.all(waitOn).then(function () {
|
||||||
// Notice that even if we destroying handler, resolved response promise
|
// Notice that even if we destroying handler, resolved response promise
|
||||||
// must be sent back.
|
// must be sent back.
|
||||||
handler.destroy();
|
handler.close(new AbortException('Worker was terminated'));
|
||||||
handler = null;
|
handler = null;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -15,11 +15,11 @@
|
|||||||
/* globals requirejs, __non_webpack_require__ */
|
/* globals requirejs, __non_webpack_require__ */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
assert, createPromiseCapability, deprecated, getVerbosityLevel, info,
|
AbortException, assert, createPromiseCapability, deprecated,
|
||||||
InvalidPDFException, isArrayBuffer, isSameOrigin, loadJpegStream,
|
getVerbosityLevel, info, InvalidPDFException, isArrayBuffer, isSameOrigin,
|
||||||
MessageHandler, MissingPDFException, NativeImageDecoding, PageViewport,
|
loadJpegStream, MessageHandler, MissingPDFException, NativeImageDecoding,
|
||||||
PasswordException, StatTimer, stringToBytes, UnexpectedResponseException,
|
PageViewport, PasswordException, StatTimer, stringToBytes,
|
||||||
UnknownErrorException, Util, warn
|
UnexpectedResponseException, UnknownErrorException, Util, warn
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import {
|
import {
|
||||||
DOMCanvasFactory, DOMCMapReaderFactory, getDefaultSetting,
|
DOMCanvasFactory, DOMCMapReaderFactory, getDefaultSetting,
|
||||||
@ -1382,7 +1382,7 @@ var PDFWorker = (function PDFWorkerClosure() {
|
|||||||
var messageHandler = new MessageHandler('main', 'worker', worker);
|
var messageHandler = new MessageHandler('main', 'worker', worker);
|
||||||
var terminateEarly = () => {
|
var terminateEarly = () => {
|
||||||
worker.removeEventListener('error', onWorkerError);
|
worker.removeEventListener('error', onWorkerError);
|
||||||
messageHandler.destroy();
|
messageHandler.close(new Error('Worker was terminated'));
|
||||||
worker.terminate();
|
worker.terminate();
|
||||||
if (this.destroyed) {
|
if (this.destroyed) {
|
||||||
this._readyCapability.reject(new Error('Worker was destroyed'));
|
this._readyCapability.reject(new Error('Worker was destroyed'));
|
||||||
@ -1424,7 +1424,7 @@ var PDFWorker = (function PDFWorkerClosure() {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
this._setupFakeWorker();
|
this._setupFakeWorker();
|
||||||
messageHandler.destroy();
|
messageHandler.close(new Error('Worker was terminated'));
|
||||||
worker.terminate();
|
worker.terminate();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1527,7 +1527,7 @@ var PDFWorker = (function PDFWorkerClosure() {
|
|||||||
pdfWorkerPorts.delete(this._port);
|
pdfWorkerPorts.delete(this._port);
|
||||||
this._port = null;
|
this._port = null;
|
||||||
if (this._messageHandler) {
|
if (this._messageHandler) {
|
||||||
this._messageHandler.destroy();
|
this._messageHandler.close(new AbortException('Worker was destroyed'));
|
||||||
this._messageHandler = null;
|
this._messageHandler = null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -1607,7 +1607,7 @@ var WorkerTransport = (function WorkerTransportClosure() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.messageHandler) {
|
if (this.messageHandler) {
|
||||||
this.messageHandler.destroy();
|
this.messageHandler.close(new AbortException('Worker was destroyed'));
|
||||||
this.messageHandler = null;
|
this.messageHandler = null;
|
||||||
}
|
}
|
||||||
this.destroyCapability.resolve();
|
this.destroyCapability.resolve();
|
||||||
|
@ -1632,8 +1632,33 @@ MessageHandler.prototype = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy() {
|
close(reason) {
|
||||||
this.comObj.removeEventListener('message', this._onComObjOnMessage);
|
this.comObj.removeEventListener('message', this._onComObjOnMessage);
|
||||||
|
|
||||||
|
// Reject all promises and streams.
|
||||||
|
for (let i in this.callbacksCapabilities) {
|
||||||
|
const callbackCapability = this.callbacksCapabilities[i];
|
||||||
|
callbackCapability.reject(reason);
|
||||||
|
}
|
||||||
|
for (let i in this.streamSinks) {
|
||||||
|
const sink = this.streamSinks[i];
|
||||||
|
sink.sinkCapability.reject(reason);
|
||||||
|
}
|
||||||
|
for (let i in this.streamControllers) {
|
||||||
|
const controller = this.streamControllers[i];
|
||||||
|
if (!controller.isClosed) {
|
||||||
|
controller.controller.error(reason);
|
||||||
|
}
|
||||||
|
if (controller.startCall) {
|
||||||
|
controller.startCall.reject(reason);
|
||||||
|
}
|
||||||
|
if (controller.pullCall) {
|
||||||
|
controller.pullCall.reject(reason);
|
||||||
|
}
|
||||||
|
if (controller.cancelCall) {
|
||||||
|
controller.cancelCall.reject(reason);
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user