tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2019-01-11 04:17:47 +03:00
parent 7747229c18
commit 20d0ed8741
2 changed files with 11 additions and 5 deletions

View File

@ -794,7 +794,8 @@ var FileSystemLoaderActions = actions.Actions({
logger.emit('queued', gid)}) logger.emit('queued', gid)})
// XXX get this from config... // XXX get this from config...
var chunk_size = 50 //var chunk_size = 50
var chunk_size = '100C'
return this.images return this.images
.map(function(gid, image){ .map(function(gid, image){

View File

@ -231,12 +231,12 @@ var makeChunkIter = function(iter, wrapper){
var that = this var that = this
var args = [...arguments] var args = [...arguments]
size = args[0] instanceof Function ? size = args[0] instanceof Function ?
(this.chunk_size || 50) (this.CHUNK_SIZE || 50)
: args.shift() : args.shift()
size = typeof(size) == typeof('str') ? size = typeof(size) == typeof('str') ?
// number of chunks... // number of chunks...
(size.endsWith('c') || size.endsWith('C') ? (size.trim().endsWith('c') || size.trim().endsWith('C') ?
Math.round(this.length / parseInt(size)) Math.round(this.length / (parseInt(size) || 1)) || 1
: parseInt(size)) : parseInt(size))
: size : size
func = args.shift() func = args.shift()
@ -250,6 +250,11 @@ var makeChunkIter = function(iter, wrapper){
// ...I do not like the idea of using recursion // ...I do not like the idea of using recursion
// here because of the stack size issue which would // here because of the stack size issue which would
// break the code on very large arrays... // break the code on very large arrays...
// ...this might not be the case as on setTimeout(..)
// we should be dropping the frame, the only thing that
// may keep in memory is the closure, but in theory the
// calling function will return by the time the next is
// called (test!)
// ...is there a different way to do this? // ...is there a different way to do this?
var next = function(chunks){ var next = function(chunks){
setTimeout(function(){ setTimeout(function(){
@ -294,7 +299,7 @@ var makeChunkIter = function(iter, wrapper){
//*/ //*/
}) } } }) } }
Array.prototype.chunk_size = 50 Array.prototype.CHUNK_SIZE = 50
Array.prototype.mapChunks = makeChunkIter('map') Array.prototype.mapChunks = makeChunkIter('map')
Array.prototype.filterChunks = makeChunkIter('map', Array.prototype.filterChunks = makeChunkIter('map',
function(res, func, array, e){ function(res, func, array, e){