mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-30 10:50:08 +00:00
added pool to export...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
ac44bdd9b3
commit
b319760129
65
ui/files.js
65
ui/files.js
@ -842,7 +842,13 @@ function exportImagesTo(path, im_name, dir_name, size){
|
|||||||
selection.sort(imageOrderCmp)
|
selection.sort(imageOrderCmp)
|
||||||
var z = (('10e' + (selection.length + '').length) * 1 + '').slice(2)
|
var z = (('10e' + (selection.length + '').length) * 1 + '').slice(2)
|
||||||
|
|
||||||
var queue = []
|
var res = $.Deferred()
|
||||||
|
var pool_size = 100
|
||||||
|
var pool = makeDefferedPool(pool_size)
|
||||||
|
.depleted(function(){
|
||||||
|
showStatusQ('Export: done.')
|
||||||
|
res.resolve()
|
||||||
|
})
|
||||||
|
|
||||||
// go through ribbons...
|
// go through ribbons...
|
||||||
for(var i=DATA.ribbons.length-1; i >= 0; i--){
|
for(var i=DATA.ribbons.length-1; i >= 0; i--){
|
||||||
@ -860,67 +866,12 @@ function exportImagesTo(path, im_name, dir_name, size){
|
|||||||
var o = selection.indexOf(gid) + ''
|
var o = selection.indexOf(gid) + ''
|
||||||
dest = dest.replace('%i', (z + o).slice(o.length))
|
dest = dest.replace('%i', (z + o).slice(o.length))
|
||||||
|
|
||||||
queue.push([gid, path, dest, size])
|
pool.enqueue(null, exportImageTo, [gid, path, dest, size])
|
||||||
}
|
}
|
||||||
|
|
||||||
path = normalizePath(path +'/'+ dir_name)
|
path = normalizePath(path +'/'+ dir_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
var res = []
|
|
||||||
// XXX pool this...
|
|
||||||
queue.forEach(function(e){
|
|
||||||
res.push(exportImageTo.apply(null, e))
|
|
||||||
})
|
|
||||||
|
|
||||||
return $.when.apply(null, res)
|
|
||||||
.done(function(){
|
|
||||||
showStatusQ('Export: done.')
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
|
|
||||||
// XXX make this generic...
|
|
||||||
var pool = []
|
|
||||||
var pool_size = 100
|
|
||||||
var res = $.Deferred()
|
|
||||||
|
|
||||||
var enqueue = function(e){
|
|
||||||
if(e == null){
|
|
||||||
return
|
|
||||||
}
|
|
||||||
var worker = exportImageTo.apply(null, e)
|
|
||||||
.done(function(){
|
|
||||||
// prepare remove self from pool...
|
|
||||||
var i = pool.indexOf(worker)
|
|
||||||
|
|
||||||
// get the next queue item...
|
|
||||||
var next = queue.splice(0, 1)[0]
|
|
||||||
|
|
||||||
// enqueue the next worker if it exists...
|
|
||||||
if(next != null){
|
|
||||||
// replace self with next worker...
|
|
||||||
pool[i] = enqueue(next)
|
|
||||||
|
|
||||||
// nothing in queue...
|
|
||||||
} else {
|
|
||||||
// remove self...
|
|
||||||
pool.splice(i, 1)
|
|
||||||
|
|
||||||
// empty queue and empty pool mean we are done...
|
|
||||||
if(pool.length == 0){
|
|
||||||
showStatusQ('Export: done.')
|
|
||||||
res.resolve()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.fail(function(){
|
|
||||||
var i = pool.indexOf(worker)
|
|
||||||
// remove self...
|
|
||||||
pool.splice(i, 1)
|
|
||||||
})
|
|
||||||
return worker
|
|
||||||
}
|
|
||||||
pool = queue.splice(0, pool_size).map(enqueue)
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -733,7 +733,7 @@ function makeDefferedPool(size){
|
|||||||
queue: [],
|
queue: [],
|
||||||
}
|
}
|
||||||
|
|
||||||
pool._done_handlers = []
|
pool._deplete_handlers = []
|
||||||
|
|
||||||
pool._run = function(obj, func, args){
|
pool._run = function(obj, func, args){
|
||||||
var that = this
|
var that = this
|
||||||
@ -770,7 +770,7 @@ function makeDefferedPool(size){
|
|||||||
|
|
||||||
// empty queue and empty pool mean we are done...
|
// empty queue and empty pool mean we are done...
|
||||||
if(pool.length == 0){
|
if(pool.length == 0){
|
||||||
that._done()
|
that._deplete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,7 +799,7 @@ function makeDefferedPool(size){
|
|||||||
|
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
pool._done(){
|
pool._deplete(){
|
||||||
var that = this
|
var that = this
|
||||||
this._done_handlers.forEach(function(func){
|
this._done_handlers.forEach(function(func){
|
||||||
func(that)
|
func(that)
|
||||||
@ -814,8 +814,9 @@ function makeDefferedPool(size){
|
|||||||
// start work if we have not already...
|
// start work if we have not already...
|
||||||
this._fill()
|
this._fill()
|
||||||
}
|
}
|
||||||
pool.done = function(func){
|
// This is called after the pool is populated and depleted...
|
||||||
this._done_handlers.push(func)
|
pool.depleted = function(func){
|
||||||
|
this._deplete_handlers.push(func)
|
||||||
}
|
}
|
||||||
|
|
||||||
return pool
|
return pool
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user