Merge pull request #11118 from Snuffleupagus/FetchBuiltInCMap-sendWithStream

Transfer, rather than copy, CMap data to the worker-thread
This commit is contained in:
Tim van der Meij 2019-09-06 22:56:14 +02:00 committed by GitHub
commit 37d5b80ba8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 5 deletions

View file

@ -2225,11 +2225,26 @@ class WorkerTransport {
});
});
messageHandler.on('FetchBuiltInCMap', (data) => {
messageHandler.on('FetchBuiltInCMap', (data, sink) => {
if (this.destroyed) {
return Promise.reject(new Error('Worker was destroyed'));
sink.error(new Error('Worker was destroyed'));
return;
}
return this.CMapReaderFactory.fetch(data);
let fetched = false;
sink.onPull = () => {
if (fetched) {
sink.close();
return;
}
fetched = true;
this.CMapReaderFactory.fetch(data).then(function(builtInCMap) {
sink.enqueue(builtInCMap, 1, [builtInCMap.cMapData.buffer]);
}).catch(function(reason) {
sink.error(reason);
});
};
});
}