mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-11-01 11:50:07 +00:00
some work on the global worker queue and related API...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
a8d9d0ebd8
commit
3c9322a4fe
@ -357,18 +357,16 @@ if(window.CEF_dumpJSON != null){
|
||||
}))
|
||||
}
|
||||
|
||||
window._PREVIW_CREATE_QUEUE = null
|
||||
|
||||
// Queued version of makeImagesPreviews(...)
|
||||
window.makeImagesPreviewsQ = function(gids, sizes, mode){
|
||||
gids = gids == null ? getClosestGIDs() : gids
|
||||
|
||||
// attach the the previous queue...
|
||||
if(_PREVIW_CREATE_QUEUE == null){
|
||||
if(WORKERS.preview_generator == null){
|
||||
var queue = makeDeferredsQ()
|
||||
_PREVIW_CREATE_QUEUE = queue.start()
|
||||
WORKERS.preview_generator = queue.start()
|
||||
} else {
|
||||
var queue = _PREVIW_CREATE_QUEUE
|
||||
var queue = WORKERS.preview_generator
|
||||
}
|
||||
|
||||
// attach the workers to the queue...
|
||||
|
||||
21
ui/data.js
21
ui/data.js
@ -143,6 +143,9 @@ var UPDATE_SORT_ENABLED = false
|
||||
// XXX for some reason the sync version appears to work faster...
|
||||
var UPDATE_SYNC = false
|
||||
|
||||
// object to register all the worker queues...
|
||||
var WORKERS = {}
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
@ -1174,7 +1177,19 @@ function getPrevLocation(){
|
||||
* Actions...
|
||||
*/
|
||||
|
||||
/******************************************************** Extension **/
|
||||
/********************************************************* Workers ***/
|
||||
|
||||
function killAllWorkers(){
|
||||
for(var k in WORKERS){
|
||||
console.log('Worker: Stopping:', k)
|
||||
WORKERS[k].kill()
|
||||
}
|
||||
WORKERS = {}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/******************************************************* Extension ***/
|
||||
|
||||
// Open image in an external editor/viewer
|
||||
//
|
||||
@ -1196,7 +1211,7 @@ function openImageWith(prog){
|
||||
|
||||
|
||||
|
||||
/********************************************************** Sorting **/
|
||||
/********************************************************* Sorting ***/
|
||||
|
||||
function reverseImageOrder(){
|
||||
DATA.order.reverse()
|
||||
@ -1227,7 +1242,7 @@ function sortImagesByName(reverse){
|
||||
|
||||
|
||||
|
||||
/*************************************************** Manual sorting **/
|
||||
/************************************************** Manual sorting ***/
|
||||
|
||||
// Ordering images...
|
||||
// NOTE: this a bit more complicated than simply shifting an image
|
||||
|
||||
19
ui/files.js
19
ui/files.js
@ -539,6 +539,11 @@ function loadDir(path, no_preview_processing, prefix){
|
||||
prefix = prefix == null ? 'Data' : prefix
|
||||
prefix = prefix === false ? null : prefix
|
||||
|
||||
// stop all workers running on current image set before we
|
||||
// move to the next...
|
||||
// XXX is this the correct sopot for this???
|
||||
killAllWorkers()
|
||||
|
||||
IMAGES_CREATED = false
|
||||
|
||||
path = normalizePath(path)
|
||||
@ -669,6 +674,10 @@ function updateImageOrientation(gid, no_update_loaded){
|
||||
gid = gid == null ? getImageGID() : gid
|
||||
var img = IMAGES[gid]
|
||||
|
||||
if(img == null){
|
||||
return
|
||||
}
|
||||
|
||||
return getImageOrientation(normalizePath(img.path))
|
||||
.done(function(o){
|
||||
var o_o = img.orientation
|
||||
@ -712,7 +721,15 @@ function updateImagesOrientation(gids, no_update_loaded){
|
||||
function updateImagesOrientationQ(gids, no_update_loaded){
|
||||
gids = gids == null ? getClosestGIDs() : gids
|
||||
|
||||
var queue = makeDeferredsQ().start()
|
||||
//var queue = makeDeferredsQ().start()
|
||||
// attach the the previous queue...
|
||||
if(WORKERS.image_orientation_reader == null){
|
||||
var queue = makeDeferredsQ()
|
||||
WORKERS.image_orientation_reader = queue.start()
|
||||
} else {
|
||||
var queue = WORKERS.image_orientation_reader
|
||||
}
|
||||
|
||||
var last = null
|
||||
|
||||
// attach workers to queue...
|
||||
|
||||
@ -594,7 +594,7 @@ jQuery.fn.sortChildren = function(func){
|
||||
// .kill()
|
||||
// Stop the queue, preventing any new workers from starting.
|
||||
// NOTE: this will not kill the currently running worker.
|
||||
// NOTE: after killing a queue it can not be restarted.
|
||||
// NOTE: after a queue is killed it can not be restarted.
|
||||
//
|
||||
// .isWorking()
|
||||
// will return true if there is at least one worker still not
|
||||
@ -623,27 +623,41 @@ function makeDeferredsQ(first){
|
||||
// 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.
|
||||
queue.enqueue = function(deffered){
|
||||
queue.enqueue = function(worker){
|
||||
var cur = $.Deferred()
|
||||
var args = Array.apply(null, arguments).slice(1)
|
||||
|
||||
last.done(function(){
|
||||
|
||||
// see if we are killed...
|
||||
if(queue.state() == 'resolved'){
|
||||
// this will kill the queue as we continue only on success...
|
||||
cur.reject()
|
||||
return
|
||||
}
|
||||
|
||||
// do the work...
|
||||
deffered.apply(null, args)
|
||||
function run(){
|
||||
return worker.apply(null, args)
|
||||
.done(function(o){
|
||||
cur.resolve(o)
|
||||
})
|
||||
.fail(function(){
|
||||
cur.resolve('fail')
|
||||
})
|
||||
}
|
||||
|
||||
last.done(function(){
|
||||
|
||||
// XXX one way to stop and resume the queue execution is:
|
||||
// 1) add a "suspended" state
|
||||
// 2) in the "suspended" state bind the worker start to
|
||||
// .resume(...)
|
||||
if(queue.state() == 'suspended'){
|
||||
queue.resumed(function(){
|
||||
run()
|
||||
})
|
||||
|
||||
// if we are killed drop the work...
|
||||
} else if(queue.state() == 'resolved'){
|
||||
// this will kill the queue as we continue only on success...
|
||||
cur.reject()
|
||||
return
|
||||
|
||||
// do the work now...
|
||||
} else {
|
||||
run()
|
||||
}
|
||||
})
|
||||
|
||||
last = cur
|
||||
@ -663,6 +677,24 @@ function makeDeferredsQ(first){
|
||||
return this
|
||||
}
|
||||
|
||||
/* XXX suspend interface...
|
||||
// XXX change the state...
|
||||
queue.suspend = function(){
|
||||
// XXX
|
||||
return this
|
||||
}
|
||||
// XXX change the state...
|
||||
queue.resume = function(){
|
||||
// XXX
|
||||
return this
|
||||
}
|
||||
// XXX change the state...
|
||||
queue.resumed = function(){
|
||||
// XXX
|
||||
return this
|
||||
}
|
||||
*/
|
||||
|
||||
// Report work state...
|
||||
// XXX make this a propper state, or integrate into the deferred in
|
||||
// a more natural way...
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user