reworked core.debounce(..) + moved to actions.debounce(..) for status bar updates...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-12-03 04:03:20 +03:00
parent 7122c619f4
commit f850d2df18
7 changed files with 80 additions and 60 deletions

View File

@ -1373,8 +1373,12 @@ module.Cache = ImageGridFeatures.Feature({
// timeout: number,
// returns: 'cached' | 'dropped',
// callback: function(retriggered, args),
//
// postcall: true,
// }
//
// XXX might be a good ide to move this someplace generic...
// XXX this is not debouncing pre/post calls, just the base action...
var debounce =
module.debounce =
function(options, func){
@ -1383,52 +1387,67 @@ function(options, func){
func = args.pop()
options = args.pop() || {}
if(typeof(options) == typeof(123)){
options.timeout = options
}
typeof(options) == typeof(123)
&& (options.timeout = options)
// closure state...
var res = undefined
var res
var last_args
var debounced = false
var retriggered = 0
var f = function(...args){
if(!debounced){
res = func instanceof Function ?
func.call(this, ...args)
// alias...
: this.parseStringAction.callAction(this, func, ...args)
res = options.returns != 'cahced' ? res : undefined
// call the action...
var call = function(context, ...args){
return func instanceof Function ?
func.call(context, ...args)
// alias...
: this.parseStringAction.callAction(context, func, ...args) }
// start the timer...
debounced = setTimeout(
function(){
// callback...
options.callback instanceof Function
&& options.callback.call(this, retriggered, args)
return object.mixin(
function(...args){
var retrigger
// call...
if(!debounced){
res = call(this, ...args)
res = options.returns != 'cahced' ?
res
: undefined
// cleanup...
retriggered = 0
res = undefined
debounced = false
}.bind(this),
options.timeout
|| this.config['debounce-action-timeout']
|| 200)
// start the timer...
debounced = setTimeout(
function(){
var c
// callback...
options.callback instanceof Function
&& (c = options.callback.call(this, retriggered, args))
// retrigger...
options.postcall
&& retriggered > 0
&& c !== false
// XXX should this be a debounced call or a normal call...
// XXX this is not the actual action thus no
// handlers will be triggered...
&& call(this, ...last_args)
// cleanup...
retriggered = 0
res = undefined
debounced = false }.bind(this),
options.timeout
|| this.config['debounce-action-timeout']
|| 200)
// skip...
} else {
retriggered++
last_args = args
return res } },
{
toString: function(){
return `// debounced...\n${
doc([ func instanceof Function ?
func.toString()
: func ])}` },
}) }
} else {
retriggered++
return res
}
}
f.toString = function(){
return `// debounced...\n${
doc([ func instanceof Function ? func.toString() : func ])}`
}
return f
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -2590,8 +2609,6 @@ function(name, func){
opts || {},
{ handler: function(item){
return func.call(that, item, ...args) } }))
sync
&& (q.sync_start = true)
// pre-process args...
arg_handler
&& ([items, ...args] =
@ -2602,10 +2619,9 @@ function(name, func){
var res = new Promise(function(resolve, reject){
q.then(resolve, reject) })
// sync start...
// NOTE: we need to explicitly .start() here because the
// queue could be waiting for a timeout
sync
&& q.start()
// NOTE: we need to explicitly .start(true) here because the
// queue could be waiting for a timeout...
q.start(sync)
return res }),
{
toString: function(){
@ -2732,6 +2748,7 @@ var TaskActions = actions.Actions({
|| queue.clear() }
var cleanup = function(){
return function(){
queue.stop()
// XXX handle error state...
//logger
// && logger.emit('close')

View File

@ -299,10 +299,10 @@ var ExampleActions = actions.Actions({
reverse
&& items.reverse()
return [items, ...args] },
function(item, ...args){
console.log('Queue handler action!!', item, ...args)
function(item, timeout, ...args){
console.log('Queue handler action!!', item, timeout, ...args)
return new Promise(function(resolve){
setTimeout(resolve, 100) }) })],
setTimeout(resolve, timeout || 100) }) })],
//
// NOTE: action name and task name should be the same to avoid

View File

@ -116,13 +116,14 @@ var MetadataReaderActions = actions.Actions({
NOTE: also see: .cacheMetadata(..)
`,
core.queueHandler('Read image metadata',
function(image, force){
{quiet: true},
function(queue, image, force){
return [
images == 'all' ?
image == 'all' ?
this.images.keys()
: images == 'loaded' ?
: image == 'loaded' ?
this.data.getImages('loaded')
: images,
: image,
force,
] },
function(image, force){

View File

@ -638,7 +638,8 @@ var SharpActions = actions.Actions({
NOTE: for info on full metadata format see: .readMetadata(..)
`,
core.queueHandler('Cache image metadata',
{quiet: true},
// XXX timeouts still need tweaking...
{quiet: true, pool_size: 2, busy_timeout: 400},
// parse args...
function(queue, image, logger){
var force = false

View File

@ -635,6 +635,7 @@ var StatusBarActions = actions.Actions({
handler.call(that, item, gid, img) } }) } },
null)],
updateStatusBar: ['- Interface/Update satus bar',
{precall: actions.debounce()},
'toggleStatusBar: "!"'],
resetStatusBar: ['Interface/Reset status bar',

View File

@ -1073,9 +1073,9 @@
"integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg=="
},
"ig-actions": {
"version": "3.24.19",
"resolved": "https://registry.npmjs.org/ig-actions/-/ig-actions-3.24.19.tgz",
"integrity": "sha512-b4Lz4qD/aw7MOcNDgGn/y6992EjeFHQw6tmv1AfX1ZeWdpg9TjPjkdFy5NLpdGknURM/b1I06AkxYLgBAeOQyQ==",
"version": "3.24.20",
"resolved": "https://registry.npmjs.org/ig-actions/-/ig-actions-3.24.20.tgz",
"integrity": "sha512-V5jOhwxjRMoNS1vT6O0nZKh9063FAxtnQoo4G/iH1Kf9jKGqDNlXY4WhoimxGdJF9cdYs+LGxLFjkjek+jaAcg==",
"requires": {
"ig-object": "^5.4.12"
}
@ -1110,9 +1110,9 @@
"integrity": "sha512-9kZM80Js9/eTwXN9VXwLDC1wDJ7gIAdYU9GIzb5KJmNcLAMaW+zhgFrwFFMrcSfggUuadgnqSrS41E4XLe8JZw=="
},
"ig-types": {
"version": "5.0.32",
"resolved": "https://registry.npmjs.org/ig-types/-/ig-types-5.0.32.tgz",
"integrity": "sha512-AKfatN0z3hURn9J7JSCaImZnkpr42WMozVLBJeAeC0urkLEU3NUcMEmuDR57dsI5vu9A3d+tyIiRxd5If/3VaQ==",
"version": "5.0.34",
"resolved": "https://registry.npmjs.org/ig-types/-/ig-types-5.0.34.tgz",
"integrity": "sha512-HQADOcjAqkZ++lVavo8lb+qzcbkd33lshgf2/TMXAh4DJLxIIioNj8skPpKjzK0BQMHxd5wvPCwGt29s/ydg5g==",
"requires": {
"ig-object": "^5.4.12",
"object-run": "^1.0.1"

View File

@ -28,11 +28,11 @@
"generic-walk": "^1.4.0",
"glob": "^7.1.6",
"guarantee-events": "^1.0.0",
"ig-actions": "^3.24.19",
"ig-actions": "^3.24.20",
"ig-argv": "^2.15.0",
"ig-features": "^3.4.2",
"ig-object": "^5.4.12",
"ig-types": "^5.0.32",
"ig-types": "^5.0.34",
"moment": "^2.29.1",
"object-run": "^1.0.1",
"requirejs": "^2.3.6",