mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-11-01 20:00:10 +00:00
makeDeferredQ(...) now done, tested and documented...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
fa633143dd
commit
5d996e5d42
@ -364,56 +364,28 @@ if(window.CEF_dumpJSON != null){
|
||||
window._PREVIW_CREATE_QUEUE = null
|
||||
// Queued version of makeImagesPreviews(...)
|
||||
//
|
||||
// XXX make a generic deferred queue...
|
||||
// XXX is this robust enough???
|
||||
// of one deferred hangs or breaks without finalizing this will
|
||||
// stall the whole queue...
|
||||
// ...need a way to jumpstart it again...
|
||||
// XXX check if we are leaking the tail...
|
||||
// XXX test progress...
|
||||
// ...gets collected but the structure is a tad too complex...
|
||||
// - should we make it flat???
|
||||
// - do we need all that data????
|
||||
// NOTE: this will remove the old deferred if it us resolved, thus
|
||||
// clearing the "log" of previous operations, unless keep_log
|
||||
// is set to true...
|
||||
// XXX need a way to cancel this...
|
||||
window.makeImagesPreviewsQ = function(gids, sizes, mode, keep_log){
|
||||
window.makeImagesPreviewsQ = function(gids, sizes, mode){
|
||||
gids = gids == null ? getClosestGIDs() : gids
|
||||
var previews = []
|
||||
|
||||
$.each(gids, function(i, e){
|
||||
var deferred = $.Deferred()
|
||||
|
||||
var last = previews[previews.length-1]
|
||||
|
||||
// first in this set -- attach to the queue...
|
||||
if(last == null){
|
||||
if(_PREVIW_CREATE_QUEUE == null
|
||||
|| (!keep_log && _PREVIW_CREATE_QUEUE.state() == 'resolved')){
|
||||
// if nothing in queue, start at once...
|
||||
last = $.Deferred().resolve()
|
||||
// attach the the previous queue...
|
||||
if(_PREVIW_CREATE_QUEUE == null){
|
||||
var queue = makeDeferredsQ()
|
||||
_PREVIW_CREATE_QUEUE = queue.start()
|
||||
} else {
|
||||
last = _PREVIW_CREATE_QUEUE
|
||||
}
|
||||
var queue = _PREVIW_CREATE_QUEUE
|
||||
}
|
||||
|
||||
// append to deffered queue...
|
||||
last.always(function(){
|
||||
makeImagePreviews(e, sizes, mode)
|
||||
.progress(function(state){
|
||||
deferred.notify(state)
|
||||
})
|
||||
.always(function(){
|
||||
deferred.resolve()
|
||||
})
|
||||
$.each(gids, function(_, gid){
|
||||
queue.enqueue(makeImagePreviews, gid, sizes, mode)
|
||||
//.progress(function(state){ queue.notify(state) })
|
||||
.always(function(){ queue.notify(gid, 'done') })
|
||||
})
|
||||
|
||||
previews.push(deferred)
|
||||
})
|
||||
|
||||
_PREVIW_CREATE_QUEUE = $.when.apply(null, previews)
|
||||
return _PREVIW_CREATE_QUEUE
|
||||
return queue
|
||||
}
|
||||
|
||||
window.makeImageGID = function(source, make_text_gid){
|
||||
|
||||
@ -678,11 +678,38 @@ function assyncCall(func){
|
||||
}
|
||||
|
||||
|
||||
// XXX needs more docs...
|
||||
// XXX needs a better public inteface...
|
||||
function makeDeferredsQ(){
|
||||
// Deferred worker queue
|
||||
//
|
||||
// This will either create a new queue or attach to the tail of an
|
||||
// existing queue (deferred) if given.
|
||||
//
|
||||
// This will return a deferred object with several extensions:
|
||||
//
|
||||
// .enqueue(worker, ...)
|
||||
// Add a worker to the queue.
|
||||
// A worker is executed when the previous worker is resolved.
|
||||
// A worker must return a deferred.
|
||||
//
|
||||
// .start()
|
||||
// Start the first worker.
|
||||
//
|
||||
// .kill()
|
||||
// Stop the queue, preventing any new workers from starting.
|
||||
// NOTE: this will not kill the currently running worker.
|
||||
//
|
||||
// .isWorking()
|
||||
// will return true if there is at least one worker still not
|
||||
// resolved, false otherwise.
|
||||
// NOTE: if the queue is killed, this will always return false.
|
||||
//
|
||||
//
|
||||
// NOTE: one queue is guaranteed to work in a sequence, to run several
|
||||
// pipelines in parallel use two or more queues.
|
||||
// NOTE: running queues in parallel depends on the actual context in
|
||||
// use (browser/node.js/...).
|
||||
function makeDeferredsQ(first){
|
||||
first = first == null ? $.Deferred() : first
|
||||
|
||||
var first = $.Deferred()
|
||||
var last = first
|
||||
|
||||
// this is used for two things:
|
||||
@ -735,7 +762,14 @@ function makeDeferredsQ(){
|
||||
this.resolve()
|
||||
return this
|
||||
}
|
||||
|
||||
// XXX make this a propper state, or integrate into the deferred in
|
||||
// a more natural way...
|
||||
monitor.isWorking = function(){
|
||||
if(monitor.state() != 'resolved' && last.state() != 'resolved'){
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
return monitor
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user