From 74876cf255d95d8309c9c7cb861a391c1c0a90ae Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 11 Jul 2013 03:04:11 +0400 Subject: [PATCH] added a generic deffered queue... Signed-off-by: Alex A. Naanou --- ui/files.js | 10 ++++----- ui/lib/jli.js | 57 +++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/ui/files.js b/ui/files.js index c1a83a78..a8bdccc7 100755 --- a/ui/files.js +++ b/ui/files.js @@ -716,13 +716,14 @@ function updateImagesOrientation(gids, no_update_loaded){ // function updateImagesOrientationQ(gids, no_update_loaded){ gids = gids == null ? getClosestGIDs() : gids - //var res = [] var last = $.Deferred().resolve() // this is used for two things: // - report progress // - kill the queue if needed... + // XXX make this a deferred-like cleanly rather than bu monkey patching... + // XXX do we need to make this resumable?? var monitor = $.Deferred() monitor.killed = false monitor.kill = function(){ @@ -732,12 +733,15 @@ function updateImagesOrientationQ(gids, no_update_loaded){ $.each(gids, function(_, gid){ var cur = $.Deferred() last.done(function(){ + // see if we are killed... if(monitor.killed == true){ monitor.notify('killed') monitor.resolve() + // this will kill the queue as we continue only on success... cur.reject() return } + // do the work... updateImageOrientation(gid, no_update_loaded) .done(function(o){ cur.resolve(o) @@ -750,12 +754,8 @@ function updateImagesOrientationQ(gids, no_update_loaded){ }) last = cur - //res.push(cur) }) - // NOTE: .when(...) is used to add more introspecitve feedback... - //return $.when.apply(null, res) - // return last last.done(function(){ monitor.resolve() }) diff --git a/ui/lib/jli.js b/ui/lib/jli.js index 631f05cc..77aa0123 100755 --- a/ui/lib/jli.js +++ b/ui/lib/jli.js @@ -678,23 +678,54 @@ function assyncCall(func){ } -/* -function chainDeferreds(deferred, after){ - after = after == null ? $.Deferred.resolve() : after +function makeDeferredsQ(){ - $.each(deferred, function(_, d){ + var first = $.Deferred().resolve() + var last = first + + // this is used for two things: + // - report progress + // - kill the queue if needed... + // XXX make this a deferred-like cleanly rather than bu monkey patching... + // XXX do we need to make this resumable?? + var monitor = $.Deferred() + + monitor.kill = function(){ + this.resolve() + } + + monitor.enqueue = function(deffered){ var cur = $.Deferred() - after.done(function(){ - d() - .done(function(){ cur.resolve() }) - .fail(function(){ cur.reject() }) - }) - after = cur - }) + last.done(function(){ - return after + // see if we are killed... + if(monitor.state() == 'resolved'){ + // this will kill the queue as we continue only on success... + cur.reject() + return + } + + // do the work... + deffered.apply(null, Array.apply(null, arguments).slice(1)) + .done(function(o){ + cur.resolve(o) + monitor.notify('done') + }) + .fail(function(){ + cur.resolve('fail') + monitor.notify('fail') + }) + }) + + last = cur + } + + monitor.start = function(){ + first.resolve() + } + + return monitor } -*/