From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.devel Subject: Re: Return value of finished threads Date: Fri, 20 Jul 2018 12:17:46 -0400 Message-ID: References: <87h8kuq7kf.fsf@gmx.de> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1532103361 15989 195.159.176.226 (20 Jul 2018 16:16:01 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 20 Jul 2018 16:16:01 +0000 (UTC) Cc: Emacs developers To: Michael Albinus Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 20 18:15:57 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1fgY4S-00044O-Gy for ged-emacs-devel@m.gmane.org; Fri, 20 Jul 2018 18:15:56 +0200 Original-Received: from localhost ([::1]:48940 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgY6Z-000259-7Q for ged-emacs-devel@m.gmane.org; Fri, 20 Jul 2018 12:18:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fgY6G-000236-Oi for emacs-devel@gnu.org; Fri, 20 Jul 2018 12:17:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fgY6F-0001fT-Py for emacs-devel@gnu.org; Fri, 20 Jul 2018 12:17:48 -0400 Original-Received: from mail-oi0-x231.google.com ([2607:f8b0:4003:c06::231]:42597) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fgY6F-0001fD-In for emacs-devel@gnu.org; Fri, 20 Jul 2018 12:17:47 -0400 Original-Received: by mail-oi0-x231.google.com with SMTP id n84-v6so22262427oib.9 for ; Fri, 20 Jul 2018 09:17:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=rp6uj0YwyOcxHIURVqDpF5TTcIFJDHnOd7b7XFQWK8k=; b=C+AU7GI/VG2NflRnalDaeuAI5VfYP1V7mIDtj53nPSOumVWn+1OjvQRcO9Omlo0an/ 7KJ8ulal/FobT6WDyEVouGHwwOCyhud5HvhHVEvK07FpEwcuT2ykEpx01rNK4M7m3U9l P2OjJkQOGbr3zARVJC1OJqVlgFRceulUjIPYaiaZ5qdaMP8gZbc7FgY3UFlzmZohRLM9 7UvtfiuJ0WOLLp+DgNvUbUJ0gD2WQN4YNGzVN8NuC+olNLVeSofsTT9HIldrt9Wm8e2p 8lMW8jzkuA9K3hQLKSKQjs5Qg/zT75YNnWDxybqp3ORBsZytNYrGL6ZyyZPCkiXRCEYW tU4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=rp6uj0YwyOcxHIURVqDpF5TTcIFJDHnOd7b7XFQWK8k=; b=hQuoRHKMAYbfW1hT9LsmzjcxGTopRqSxelNLdgqgTa3dTOiDgPUTveLs0/PvETM8aH Tmb2gN2N11Gci2FGVEfdiaFHxdbvxaeVl4PEDhTVfpoWB6RWm8GfHK17Gm8tuOUmI51P p5BKnH0KnGb5C5s0+CcEvedy0gLbJnaw7VNM87xTYlhpDEgn0UqC0NFs+vx12bw4FQS8 5vx2wF698BRmcKXAxU1N89uZod8krc9zjZIcIsmzfemusCsQpEnZoDXf921IgjIYbv32 74wlldFM7U8fmfD+4a+Z/V9yNWJuvg6vKwdCc94mADp+QC9jhUQ2RRlQSSPM/3RMfJt6 SBkw== X-Gm-Message-State: AOUpUlHBT1/VosOcnnCk/Xl0/pIEiOoxCBU7432OY38ZGhjhNxi2MoIL HmGmsgwqef2PtyTdWchArdg/6Yd+ONtRVTv/srg= X-Google-Smtp-Source: AAOMgpdCHEjHpD5ZRBXhBcRd0WkV8Fmi8MYgi8PId3kzacZDK1hdbLs5P2Uz0qSMrLFEE82Ux5wyUAZYV6rNpvjqItM= X-Received: by 2002:aca:eb0d:: with SMTP id j13-v6mr2959644oih.304.1532103466849; Fri, 20 Jul 2018 09:17:46 -0700 (PDT) Original-Received: by 2002:a4a:3b8d:0:0:0:0:0 with HTTP; Fri, 20 Jul 2018 09:17:46 -0700 (PDT) In-Reply-To: <87h8kuq7kf.fsf@gmx.de> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4003:c06::231 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:227590 Archived-At: On 20 July 2018 at 10:56, Michael Albinus 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))