mirror of
https://github.com/flynx/ImageGrid.git
synced 2026-01-04 17:31:10 +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(...)
|
// queued version of updateImagesOrientation(...)
|
||||||
//
|
//
|
||||||
// NOTE: this will ignore errors.
|
// 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){
|
function updateImagesOrientationQ(gids, no_update_loaded){
|
||||||
gids = gids == null ? getClosestGIDs() : gids
|
gids = gids == null ? getClosestGIDs() : gids
|
||||||
|
|
||||||
var last = $.Deferred().resolve()
|
var queue = makeDeferredsQ().start()
|
||||||
|
var last = null
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
$.each(gids, function(_, gid){
|
$.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(){
|
last.done(function(){
|
||||||
// see if we are killed...
|
queue.resolve()
|
||||||
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)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
last = cur
|
return queue
|
||||||
})
|
|
||||||
|
|
||||||
last.done(function(){
|
|
||||||
monitor.resolve()
|
|
||||||
})
|
|
||||||
return monitor
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -678,9 +678,11 @@ function assyncCall(func){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// XXX needs more docs...
|
||||||
|
// XXX needs a better public inteface...
|
||||||
function makeDeferredsQ(){
|
function makeDeferredsQ(){
|
||||||
|
|
||||||
var first = $.Deferred().resolve()
|
var first = $.Deferred()
|
||||||
var last = first
|
var last = first
|
||||||
|
|
||||||
// this is used for two things:
|
// this is used for two things:
|
||||||
@ -690,12 +692,15 @@ function makeDeferredsQ(){
|
|||||||
// XXX do we need to make this resumable??
|
// XXX do we need to make this resumable??
|
||||||
var monitor = $.Deferred()
|
var monitor = $.Deferred()
|
||||||
|
|
||||||
monitor.kill = function(){
|
// Add a worker to queue...
|
||||||
this.resolve()
|
//
|
||||||
}
|
// 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){
|
monitor.enqueue = function(deffered){
|
||||||
var cur = $.Deferred()
|
var cur = $.Deferred()
|
||||||
|
var args = Array.apply(null, arguments).slice(1)
|
||||||
|
|
||||||
last.done(function(){
|
last.done(function(){
|
||||||
|
|
||||||
// see if we are killed...
|
// see if we are killed...
|
||||||
@ -706,23 +711,31 @@ function makeDeferredsQ(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do the work...
|
// do the work...
|
||||||
deffered.apply(null, Array.apply(null, arguments).slice(1))
|
deffered.apply(null, args)
|
||||||
.done(function(o){
|
.done(function(o){
|
||||||
cur.resolve(o)
|
cur.resolve(o)
|
||||||
monitor.notify('done')
|
|
||||||
})
|
})
|
||||||
.fail(function(){
|
.fail(function(){
|
||||||
cur.resolve('fail')
|
cur.resolve('fail')
|
||||||
monitor.notify('fail')
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
last = cur
|
last = cur
|
||||||
|
|
||||||
|
return cur
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start the work...
|
||||||
monitor.start = function(){
|
monitor.start = function(){
|
||||||
first.resolve()
|
first.resolve()
|
||||||
|
return this
|
||||||
}
|
}
|
||||||
|
// Kill the queue...
|
||||||
|
monitor.kill = function(){
|
||||||
|
this.resolve()
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return monitor
|
return monitor
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user