mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-12-27 13:32:01 +00:00
generic deffered queue now working (not everywhere yet)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
74876cf255
commit
fa633143dd
57
ui/files.js
57
ui/files.js
@ -709,57 +709,28 @@ function updateImagesOrientation(gids, no_update_loaded){
|
||||
// queued version of updateImagesOrientation(...)
|
||||
//
|
||||
// NOTE: this will ignore errors.
|
||||
//
|
||||
// XXX need a way to cancel this...
|
||||
// - one way is to .reject(...) any of the still pending elements,
|
||||
// but there appears no way of getting the list out of when...
|
||||
//
|
||||
function updateImagesOrientationQ(gids, no_update_loaded){
|
||||
gids = gids == null ? getClosestGIDs() : gids
|
||||
|
||||
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(){
|
||||
this.killed = true
|
||||
}
|
||||
var queue = makeDeferredsQ().start()
|
||||
var last = null
|
||||
|
||||
$.each(gids, function(_, gid){
|
||||
var cur = $.Deferred()
|
||||
last = queue.enqueue(updateImageOrientation, gid, no_update_loaded)
|
||||
.done(function(o){ queue.notify(gid, 'done') })
|
||||
.fail(function(){ queue.notify(gid, 'fail') })
|
||||
})
|
||||
|
||||
if(last != null){
|
||||
// auto-stop the queue...
|
||||
// NOTE: this is mostly for the saik of reporting...
|
||||
// XXX do we need to auto-stop this???
|
||||
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)
|
||||
monitor.notify('done', gid)
|
||||
})
|
||||
.fail(function(){
|
||||
cur.resolve('fail')
|
||||
monitor.notify('fail', gid)
|
||||
})
|
||||
queue.resolve()
|
||||
})
|
||||
}
|
||||
|
||||
last = cur
|
||||
})
|
||||
|
||||
last.done(function(){
|
||||
monitor.resolve()
|
||||
})
|
||||
return monitor
|
||||
return queue
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -678,9 +678,11 @@ function assyncCall(func){
|
||||
}
|
||||
|
||||
|
||||
// XXX needs more docs...
|
||||
// XXX needs a better public inteface...
|
||||
function makeDeferredsQ(){
|
||||
|
||||
var first = $.Deferred().resolve()
|
||||
var first = $.Deferred()
|
||||
var last = first
|
||||
|
||||
// this is used for two things:
|
||||
@ -690,12 +692,15 @@ function makeDeferredsQ(){
|
||||
// XXX do we need to make this resumable??
|
||||
var monitor = $.Deferred()
|
||||
|
||||
monitor.kill = function(){
|
||||
this.resolve()
|
||||
}
|
||||
|
||||
// Add a worker to queue...
|
||||
//
|
||||
// NOTE: .enqueue(...) accepts a worker and any number of the arguments
|
||||
// to be passed to the worker when it's its turn.
|
||||
// NOTE: the worker must porduce a deffered/promice.
|
||||
monitor.enqueue = function(deffered){
|
||||
var cur = $.Deferred()
|
||||
var args = Array.apply(null, arguments).slice(1)
|
||||
|
||||
last.done(function(){
|
||||
|
||||
// see if we are killed...
|
||||
@ -706,23 +711,31 @@ function makeDeferredsQ(){
|
||||
}
|
||||
|
||||
// do the work...
|
||||
deffered.apply(null, Array.apply(null, arguments).slice(1))
|
||||
deffered.apply(null, args)
|
||||
.done(function(o){
|
||||
cur.resolve(o)
|
||||
monitor.notify('done')
|
||||
})
|
||||
.fail(function(){
|
||||
cur.resolve('fail')
|
||||
monitor.notify('fail')
|
||||
})
|
||||
})
|
||||
|
||||
last = cur
|
||||
|
||||
return cur
|
||||
}
|
||||
|
||||
// Start the work...
|
||||
monitor.start = function(){
|
||||
first.resolve()
|
||||
return this
|
||||
}
|
||||
// Kill the queue...
|
||||
monitor.kill = function(){
|
||||
this.resolve()
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
return monitor
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user