Skip to content
/ itowns Public
forked from iTowns/itowns

Commit

Permalink
full parser registry usage
Browse files Browse the repository at this point in the history
  • Loading branch information
zarov committed Apr 12, 2018
1 parent e7f21ce commit cc623b6
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions src/Core/Scheduler/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,26 @@ function _instanciateQueue() {
// commands cancelled
cancelled: 0,
},
execute(cmd, provider, executingCounterUpToDate) {
execute(cmd, provider, parser, executingCounterUpToDate) {
if (!executingCounterUpToDate) {
this.counters.executing++;
}

// If the provider returns a Promise, use it to handle counters
// Otherwise use a resolved Promise.
var p = provider.executeCommand(cmd) || Promise.resolve();

return p.then((result) => {
this.counters.executing--;
cmd.resolve(result);
// only count successul commands
this.counters.executed++;
}, (err) => {
this.counters.executing--;
cmd.reject(err);
this.counters.failed++;
if (__DEBUG__ && this.counters.failed < 3) {
console.error(err);
}
});
return provider.executeCommand(cmd)
.then(blob => parser.parse(blob, {}))
.then((result) => {
this.counters.executing--;
cmd.resolve(result);
// only count successul commands
this.counters.executed++;
}, (err) => {
this.counters.executing--;
cmd.reject(err);
this.counters.failed++;
if (__DEBUG__ && this.counters.failed < 3) {
console.error(err);
}
});
},
};
}
Expand Down Expand Up @@ -135,7 +133,15 @@ Scheduler.prototype.runCommand = function runCommand(command, queue, executingCo
throw new Error('No known provider for layer', command.layer.id);
}

queue.execute(command, provider, executingCounterUpToDate).then(() => {
var parser = this.parsers[command.layer.format];

// we assume everything has been done so far so no need to parse it
if (!parser) {
parser = { parse: blob => blob };
// throw new Error('No known parser for layer', command.layer.id);
}

queue.execute(command, provider, parser, executingCounterUpToDate).then(() => {
// notify view that one command ended.
command.view.notifyChange('redraw' in command ? command.redraw : true, command.requester);

Expand Down

0 comments on commit cc623b6

Please sign in to comment.