help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fun with async processes


From: tomas
Subject: Re: Fun with async processes
Date: Tue, 1 Feb 2022 15:31:19 +0100

On Tue, Feb 01, 2022 at 02:54:51PM +0100, Manuel Giraud wrote:
> tomas@tuxteam.de writes:
> 
> [...]
> 
> > Nice. Many ways to go about that.
> 
> And do you think I could avoid having those defvar?

How about hiding stuff in a closure? You'll need to have lexical
environments for that:

  (defun make-sentinel-factory ()
    (let (sentinels (list))
      (lambda (tag)
        (setq sentinels (push tag sentinels)) ; FIXME: fail if already there!
        (lambda (process event)
          (when (equal "finished" event)
            (setq sentinels (delq tag sentinels))
            (message "%S is done; still left: %S" tag sentinels)
            (when (null sentinels)
              (message "All sentinels done")))))))
  
  (setq make-sentinel (make-sentinel-factory))
  
  (setq s1 (funcall make-sentinel 's1))
  (setq s2 (funcall make-sentinel 's2))
  (setq s3 (funcall make-sentinel 's3))
  
  (funcall s2 "process" "finished")
  (funcall s3 "process" "finished")
  (funcall s1 "process" "finished")

Catching errors is left as an exercise to ...

Cheers
-- 
t

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]