Add job queue full event.

This commit is contained in:
Aiosa 2024-06-01 15:02:31 +02:00
parent e0f442209b
commit cdb89ff5ad
2 changed files with 22 additions and 5 deletions

View File

@ -198,6 +198,7 @@ $.ImageLoader.prototype = {
* requests. * requests.
* @param {Function} [options.callback] - Called once image has been downloaded. * @param {Function} [options.callback] - Called once image has been downloaded.
* @param {Function} [options.abort] - Called when this image job is aborted. * @param {Function} [options.abort] - Called when this image job is aborted.
* @returns {boolean} true if job was immediatelly started, false if queued
*/ */
addJob: function(options) { addJob: function(options) {
if (!options.source) { if (!options.source) {
@ -229,10 +230,10 @@ $.ImageLoader.prototype = {
if ( !this.jobLimit || this.jobsInProgress < this.jobLimit ) { if ( !this.jobLimit || this.jobsInProgress < this.jobLimit ) {
newJob.start(); newJob.start();
this.jobsInProgress++; this.jobsInProgress++;
return true;
} }
else {
this.jobQueue.push( newJob ); this.jobQueue.push( newJob );
} return false;
}, },
/** /**

View File

@ -2042,7 +2042,7 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
var _this = this; var _this = this;
tile.loading = true; tile.loading = true;
tile.tiledImage = this; tile.tiledImage = this;
this._imageLoader.addJob({ if (!this._imageLoader.addJob({
src: tile.getUrl(), src: tile.getUrl(),
tile: tile, tile: tile,
source: this.source, source: this.source,
@ -2057,7 +2057,23 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag
abort: function() { abort: function() {
tile.loading = false; tile.loading = false;
} }
})) {
/**
* Triggered if tile load job was added to a full queue.
* This allows to react upon e.g. network not being able to serve the tiles fast enough.
* @event job-queue-full
* @memberof OpenSeadragon.Viewer
* @type {object}
* @property {OpenSeadragon.Tile} tile - The tile that failed to load.
* @property {OpenSeadragon.TiledImage} tiledImage - The tiled image the tile belongs to.
* @property {number} time - The time in milliseconds when the tile load began.
*/
this.viewer.raiseEvent("job-queue-full", {
tile: tile,
tiledImage: this,
time: time,
}); });
}
}, },
/** /**