Skip to content

Commit

Permalink
add downloads-in-progress check
Browse files Browse the repository at this point in the history
  • Loading branch information
cambecc committed Feb 26, 2014
1 parent d32d298 commit ab64a47
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
19 changes: 12 additions & 7 deletions public/libs/earth/1.0.0/earth.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,29 +242,32 @@
return when(builder(view));
}

// Some hacky stuff to ensure only one download can be in progress at a time.
var downloadsInProgress = 0;

function buildGrids() {
report.status("Downloading...");
log.time("build grids");
// UNDONE: upon failure to load a product, the unloaded product should still be stored in the agent.
// this allows us to use the product for navigation and other state.
var cancel = this.cancel;
downloadsInProgress++;
var loaded = when.map(products.productsFor(configuration.attributes), function(product) {
return product.load(cancel);
});
return when.all(loaded).then(function(products) {
log.time("build grids");
return {primaryGrid: products[0], overlayGrid: products[1] || products[0]};
}).ensure(function() {
downloadsInProgress--;
});
}

// Some hacky stuff to ensure only one layer can be downloaded at a time.
var downloadsInProgress = {}; // UNDONE: move to products module

/**
* Modifies the configuration to navigate to the chronologically next or previous data layer.
*/
function navigate(step) {
if (_.size(downloadsInProgress) > 0) { // UNDONE: correctly migrate downloadsInProgress
if (downloadsInProgress > 0) {
log.debug("Download in progress--ignoring nav request.");
return;
}
Expand Down Expand Up @@ -301,6 +304,8 @@
function drawLocationMark(point, coord) {
// show the location on the map if defined
if (fieldAgent.value() && !fieldAgent.value().isInsideBoundary(point[0], point[1])) {
// UNDONE: Sometimes this is invoked on an old, released field, because new one has not been
// built yet, causing the mark to not get drawn.
return; // outside the field boundary, so ignore.
}
if (coord && _.isFinite(coord[0]) && _.isFinite(coord[1])) {
Expand Down Expand Up @@ -406,7 +411,7 @@
*/
field.isDefined = function(x, y) {
return field(x, y)[2] !== null;
}
};

/**
* @returns {boolean} true if the point (x, y) lies inside the outer boundary of the vector field, even if
Expand All @@ -415,12 +420,12 @@
*/
field.isInsideBoundary = function(x, y) {
return field(x, y) !== NULL_WIND_VECTOR;
}
};

// Frees the massive "columns" array for GC. Without this, the array is leaked (in Chrome) each time a new
// field is interpolated because the field closure's context is leaked, for reasons that defy explanation.
field.release = function() {
columns = null;
columns = [];
};

field.randomize = function(o) { // UNDONE: this method is terrible
Expand Down
5 changes: 3 additions & 2 deletions public/libs/earth/1.0.0/products.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var products = function() {
// The OSCAR catalog is an array of file names, sorted and prefixed with yyyyMMdd. Last item is the
// most recent. For example: [ 20140101-abc.json, 20140106-abc.json, 20140112-abc.json, ... ]
oscar: µ.loadJson([OSCAR_PATH, "catalog.json"].join("/"))
}
};

function buildProduct(overrides) {
return _.extend({
Expand Down Expand Up @@ -500,7 +500,7 @@ var products = function() {
return null;
}
}
}
};

/**
* Returns the file name for the most recent OSCAR data layer to the specified date. If offset is non-zero,
Expand Down Expand Up @@ -550,6 +550,7 @@ var products = function() {
}

function dataSource(header) {
// noinspection FallthroughInSwitchStatementJS
switch (header.center || header.centerName) {
case -3:
return "OSCAR / Earth & Space Research";
Expand Down

0 comments on commit ab64a47

Please sign in to comment.