wip : replace Job by promises

This commit is contained in:
Julian Descottes 2015-04-09 17:09:13 +02:00 committed by juliandescottes
parent e6ed0c28a3
commit 281103c46e
2 changed files with 5 additions and 6 deletions

View File

@ -23,6 +23,8 @@
this.cache_[namespace] = {}; this.cache_[namespace] = {};
} }
var deferred = Q.defer();
var cache = this.cache_[namespace]; var cache = this.cache_[namespace];
var firstCacheKey = frame.getHash(); var firstCacheKey = frame.getHash();
@ -35,21 +37,20 @@
processedFrame = this.outputCloner(cache[secondCacheKey], frame); processedFrame = this.outputCloner(cache[secondCacheKey], frame);
cache[firstCacheKey] = processedFrame; cache[firstCacheKey] = processedFrame;
} else { } else {
var deferred = Q.defer();
this.frameProcessor(frame, this.onFrameProcessorComplete.bind(this, deferred, cache, firstCacheKey, secondCacheKey)); this.frameProcessor(frame, this.onFrameProcessorComplete.bind(this, deferred, cache, firstCacheKey, secondCacheKey));
return deferred.promise;
} }
} }
if (processedFrame) { if (processedFrame) {
return Q.fcall(processedFrame); deferred.resolve(processedFrame);
} }
return deferred.promise;
}; };
ns.AsyncCachedFrameProcessor.prototype.onFrameProcessorComplete = function (deferred, cache, firstCacheKey, secondCacheKey, processedFrame) { ns.AsyncCachedFrameProcessor.prototype.onFrameProcessorComplete = function (deferred, cache, firstCacheKey, secondCacheKey, processedFrame) {
cache[secondCacheKey] = processedFrame; cache[secondCacheKey] = processedFrame;
cache[firstCacheKey] = processedFrame; cache[firstCacheKey] = processedFrame;
console.log('RESOLVING');
deferred.resolve(processedFrame); deferred.resolve(processedFrame);
} }
})(); })();

View File

@ -58,8 +58,6 @@
return this.cachedFrameProcessor.get(frame); return this.cachedFrameProcessor.get(frame);
}.bind(this)) }.bind(this))
).done(function (results) { ).done(function (results) {
console.log('ALL DONE');
var colors = {}; var colors = {};
results.forEach(function (result) { results.forEach(function (result) {
Object.keys(result).forEach(function (color) { Object.keys(result).forEach(function (color) {