1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-04 15:09:16 +02:00

Add map for sections and pages, update queue to handle function without promise

This commit is contained in:
Fred Chasen 2015-05-26 19:59:06 -04:00
parent f998e5be0a
commit 5c33f9c52b
14 changed files with 1044 additions and 93 deletions

View file

@ -46,19 +46,30 @@ EPUBJS.Queue.prototype.enqueue = function() {
// Run one item
EPUBJS.Queue.prototype.dequeue = function(){
var inwait, task;
var inwait, task, result;
if(this._q.length) {
inwait = this._q.shift();
task = inwait.task;
//console.log(task)
if(task){
// Task is a function that returns a promise
return task.apply(this.context, inwait.args).then(function(){
inwait.deferred.resolve.apply(inwait.context || this.context, arguments);
}.bind(this));
result = task.apply(this.context, inwait.args);
if(result && typeof result["then"] === "function") {
// Task is a function that returns a promise
return result.then(function(){
inwait.deferred.resolve.apply(this.context, arguments);
}.bind(this));
} else {
// Task is resolves immediately
inwait.deferred.resolve.apply(this.context, result);
return inwait.promise;
}
} else {
} else if(inwait.promise) {
// Task is a promise
return inwait.promise;
}