Skip to content

kisaragi-hiu/background-job.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

background-job.el

Iterate an iterator forward in the background.

Importantly, the “job” pauses when there is user input.

Usage

First define an iterator. For example:

(iter-defun kisaragi/iter-preload-files (files)
  "Return an iterator that loads FILES."
  (dolist-with-progress-reporter (file files) "Loading files"
    (unless (get-file-buffer file)
      (iter-yield (find-file-noselect file)))))

(Note that this example requires Emacs 27 because dolist-with-progress-reporter is only added then.)

Then start the “job”:

(background-job-start
 (kisaragi/iter-preload-files
  (org-agenda-files))
 (lambda ()
   (message "All Org files loaded!")))

Interface

(background-job-start iterator callback)
return a timer; adds the timer to background-job-list
(background-job-stop timer)
cancel the timer; remove it from background-job-list

Caveats

This will make sure your “background job” never blocks user input for more than one iteration. It doesn’t help if one iteration takes a long time to run.

About

Iterate an iterator in the background, pausing on user input

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published