From: Noam Postavsky <npostavs@gmail.com>
To: Michael Albinus <michael.albinus@gmx.de>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: Return value of finished threads
Date: Fri, 20 Jul 2018 12:17:46 -0400 [thread overview]
Message-ID: <CAM-tV--6J8ynCoZ19tQAfPdvkGWOVbNeLfTOrYwnc_BCF9+ULQ@mail.gmail.com> (raw)
In-Reply-To: <87h8kuq7kf.fsf@gmx.de>
On 20 July 2018 at 10:56, Michael Albinus <michael.albinus@gmx.de> wrote:
> What I'm missing is a simple possibility to collect the return values of
> the respective finished threads (`find-file-noselect' calls), which is a
> buffer or a list of buffers. The documentation recommends the use of
> global variables, which would be inconvenient for many threads to supervise.
> What do people think?
I think you are looking for something along the lines of
promises/futures. Maybe thunk.el can be used for this (note, if trying
*scratch* remember to set lexical-binding):
;; -*- lexical-binding: t -*-
; (setq lexical-binding t) ; for *scratch*
(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))
next prev parent reply other threads:[~2018-07-20 16:17 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-20 14:56 Return value of finished threads Michael Albinus
2018-07-20 15:08 ` Eli Zaretskii
2018-07-20 15:15 ` Michael Albinus
2018-07-20 16:17 ` Clément Pit-Claudel
2018-07-20 17:25 ` Eli Zaretskii
2018-07-20 16:17 ` Noam Postavsky [this message]
2018-07-20 17:31 ` Eli Zaretskii
2018-07-21 9:28 ` Michael Albinus
2018-07-20 18:14 ` Tom Tromey
2018-07-21 9:39 ` Michael Albinus
2018-07-21 13:07 ` Tom Tromey
2018-07-21 13:16 ` Michael Albinus
2018-07-21 14:19 ` Tom Tromey
2018-07-21 14:33 ` Michael Albinus
2018-07-21 18:16 ` Tom Tromey
2018-07-21 19:33 ` Michael Albinus
2018-07-21 21:39 ` Tom Tromey
2018-07-22 10:02 ` Michael Albinus
2018-07-21 22:49 ` Brett Gilio
2018-07-22 2:18 ` Tom Tromey
2018-07-23 18:02 ` Brett Gilio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAM-tV--6J8ynCoZ19tQAfPdvkGWOVbNeLfTOrYwnc_BCF9+ULQ@mail.gmail.com \
--to=npostavs@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=michael.albinus@gmx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.