emacs-devel
[Top][All Lists]
Advanced

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

Re: Return value of finished threads


From: Eli Zaretskii
Subject: Re: Return value of finished threads
Date: Fri, 20 Jul 2018 20:31:52 +0300

> From: Noam Postavsky <address@hidden>
> Date: Fri, 20 Jul 2018 12:17:46 -0400
> Cc: Emacs developers <address@hidden>
> 
> (require 'thunk)
> (defmacro thunk-delay-in-thread (&rest body)
>   (declare (debug body))
>   (let ((result-var (make-symbol "result")))
>     `(let* ((,result-var nil)
>             (thread (make-thread
>                      (lambda ()
>                        (setq ,result-var ,(macroexp-progn body))))))
>        (thunk-delay (progn (thread-join thread) ,result-var)))))
> 
> (let ((thunks
>        (mapcar
>         (lambda (x) (thunk-delay-in-thread
>                      (message "computing square of %d" x) (* x x)))
>         (number-sequence 1 10))))
>   ;; Run this thread first, just to make things more interesting.
>   (thunk-force (nth 5 thunks))
>   ;; Get all the values.
>   (mapcar #'thunk-force thunks))

This sounds gross to me, FWIW.



reply via email to

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