Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
protected startDecodeTile() {
const payload = this.payload;
if (payload === undefined) {
logger.error("TileLoader#startDecodeTile: Cannot decode without payload");
return;
}
this.state = TileLoaderState.Decoding;
this.payload = undefined;
// Save our cancellation point, so we can be reliably cancelled by any subsequent decode
// attempts
const requestController = new RequestController(this.priority);
this.requestController = requestController;
const dataSource = this.dataSource;
this.tileDecoder
.decodeTile(payload, this.tileKey, dataSource.projection, requestController)
.then(decodedTile => {
if (requestController.signal.aborted) {
// our flow is cancelled, silently return
return;
}
this.onDecoded(decodedTile);
})
.catch(error => {
// Handle abort messages from fetch and also our own.
if (error.name === "AbortError" || error.message === "AbortError: Aborted") {
protected startDecodeTile() {
const payload = this.payload;
if (payload === undefined) {
logger.error("TileInfoLoader#startDecodeTile: Cannot decode without payload");
return;
}
this.state = TileLoaderState.Decoding;
this.payload = undefined;
// Save our cancellation point, so we can be reliably cancelled by any subsequent decode
// attempts
const requestController = new RequestController(this.priority);
this.requestController = requestController;
const dataSource = this.dataSource;
this.tileDecoder
.getTileInfo(payload, this.tileKey, dataSource.projection, requestController)
.then(tileInfo => {
if (requestController.signal.aborted) {
// our flow is cancelled, silently return
return;
}
this.tileInfo = tileInfo;
this.onDone(TileLoaderState.Ready);
})
.catch(error => {
// Handle abort messages from fetch and also our own.
entry.resolver(err, undefined);
return;
}
if (this.m_availableWorkers.length > 0) {
const worker = this.m_availableWorkers.pop()!;
if (buffers !== undefined) {
worker.postMessage(message, buffers);
} else {
worker.postMessage(message);
}
} else {
// We need a priority to keep sorting stable, so we have to add a RequestController.
if (requestController === undefined) {
requestController = new RequestController(0);
}
if (requestController.priority === 0) {
// If the requests do not get a priority, they should keep their sorting order.
requestController.priority = -this.m_nextMessageId;
}
this.m_workerRequestQueue.unshift({
message,
buffers,
requestController
});
}
}