emacs-deferred icon indicating copy to clipboard operation
emacs-deferred copied to clipboard

Skip deferred:wait-idle delay while waiting for previously deferred task to complete?

Open sten0 opened this issue 5 years ago • 0 comments

Hi,

I'm working on making a CPU-intensive function called from the modeline loop asynchronous, and am using a simple boolean var as a lock to skip body of a deferred:nextc it function when the lock is active. Unfortunately deferred:wait-idle unconditionally blocks execution of the deferred task chain. Would it be possible useful to add a third argument to its function definition? Something like a bool, that if nil will not block while waiting for the idle timer to expire (eg: skip the timer if nil). The form would become deferred:wait-idle (msec) (optional-boolean-lock).

I'm using a simple:

(deferred:$
  (deferred:wait-idle idle-wait-value)
  (deferred:next it (lambda (elapsed) set-lock-and-do-slow-CPU-intensive-stuff))
  (deferred:next it (lambda (result) format-result-as-a-string-and-set-a-var-and-unset-lock)))

The buffer-local var set in the 3rd task is evaluated in the modeline loop. The 3rd task also unsets the lock. The specific issue I'm experiencing is that the unconditional wait-idle introduces a minimum latency of 2x the idle-wait-value. In my case it might be possible to merge 2nd and 3rd tasks, but I believe other people would find it useful to be able to conditionally skip the wait-idle task, thus eliminating the guarantied latency of 1x idle-wait-value.

Thank you for maintaining emacs-deferred! Nicholas

sten0 avatar Aug 03 '19 20:08 sten0