From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#41531: 27.0.91; Better handle asynchronous eldoc backends Date: Sat, 6 Jun 2020 04:57:29 +0300 Message-ID: <63d261d3-62e5-8c60-f191-8734aa37752b@yandex.ru> References: <875zckuet9.fsf@gmail.com> <4987863b-d390-5f87-eb1c-2cca4f4b7262@yandex.ru> <87blmbrlda.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------05307B20715A0076A57CEA31" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="109154"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 Cc: 41531@debbugs.gnu.org, andreyk.mad@gmail.com To: Stefan Monnier , =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Jun 06 03:58:11 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jhO67-000SM3-7B for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 06 Jun 2020 03:58:11 +0200 Original-Received: from localhost ([::1]:40378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jhO65-0006j0-Pk for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 05 Jun 2020 21:58:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52464) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jhO5y-0006iT-0n for bug-gnu-emacs@gnu.org; Fri, 05 Jun 2020 21:58:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:38881) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jhO5x-0007Cx-OW for bug-gnu-emacs@gnu.org; Fri, 05 Jun 2020 21:58:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jhO5x-0005Hw-ND for bug-gnu-emacs@gnu.org; Fri, 05 Jun 2020 21:58:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 06 Jun 2020 01:58:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41531 X-GNU-PR-Package: emacs Original-Received: via spool by 41531-submit@debbugs.gnu.org id=B41531.159140866120298 (code B ref 41531); Sat, 06 Jun 2020 01:58:01 +0000 Original-Received: (at 41531) by debbugs.gnu.org; 6 Jun 2020 01:57:41 +0000 Original-Received: from localhost ([127.0.0.1]:50427 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jhO5c-0005HK-Vc for submit@debbugs.gnu.org; Fri, 05 Jun 2020 21:57:41 -0400 Original-Received: from mail-wm1-f49.google.com ([209.85.128.49]:35010) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jhO5a-0005H6-6z for 41531@debbugs.gnu.org; Fri, 05 Jun 2020 21:57:38 -0400 Original-Received: by mail-wm1-f49.google.com with SMTP id q25so10794506wmj.0 for <41531@debbugs.gnu.org>; Fri, 05 Jun 2020 18:57:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=JGJgGG+LBCJdCbud5Cx4q8YSPWzILkaDeg+hAAZJMRE=; b=lcmSRfiMZjMr3vST+jWxriHxlUVQG2+gZCvGaPClRyQe+JnfqSPXZLz8eCIhnBIMGg CcXgr4XAP7f4zaooJKjLr2Rj/BFsTtzR271wC+2bNmBihDIvb45v4PBPfp/50U/b+L+r pu5Y0f/O7eiIf1k5TxLyJvpn/C0hi/TUnDhMS4apd+wMSZceyEaDRjMJKQnTjZA7BHpg S8Et7qJbsQDD7GMf8JXvanUH9pmCZcb+L01gUzBkqcoCEWd6I+2/CyzYYbhe0ZrAy+zc ZIjMlgUB4v5+jBCbbC+0gucoIHITwQvozKPu2S/MqsYgvYh0dpxbGqn58SsWQDPRYqDw oBiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=JGJgGG+LBCJdCbud5Cx4q8YSPWzILkaDeg+hAAZJMRE=; b=miDVpQGaBhRN+iCtX4i3+WdxyMsZQLHwnx5Eil8mriXZx4WWT+pszdZbmm5jZmfwXJ +SbTVOCs54sccmjITeMNoA8E1R13Thy5hDKWrjsiaLWM7q06xXfSwgJ6qgY4FXI2h3Pk hpQnfCatm20/VWP63G5eckAofywhv3EboFatuNevOHcjOqfvuJ+cCZ1/KZjBDDxv9Hwj 5C/6Pgl++id4RKiTc2BmbEBCAR+KB5HMKFvfaJ5TI/ir7c1OLT3xjcmtLZv/PP8kaHAn 0H2eOsnUTM+wRjtGXzNUG0WPF0AbhUJmU/2qZNjEucp0rH9qM6sRQ8Wn0UjZmgGK1kVO kKOQ== X-Gm-Message-State: AOAM533BoCq1CXqPUz6VjO0N+5VeYs08tRXjUGtQWegwXy/b8VuIaKKD rZA57UMpO98AukfrbB/65Uk= X-Google-Smtp-Source: ABdhPJxqYUTqywXBM9fu26E3JPtCr7wTBylDzHSd8cwTVgFjDzHVaUPXbK7AQQ364CbG6X0ohAXKlA== X-Received: by 2002:a1c:c2d6:: with SMTP id s205mr5606798wmf.140.1591408652319; Fri, 05 Jun 2020 18:57:32 -0700 (PDT) Original-Received: from [192.168.0.3] ([66.205.73.129]) by smtp.googlemail.com with ESMTPSA id l18sm12646226wmj.22.2020.06.05.18.57.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 05 Jun 2020 18:57:30 -0700 (PDT) In-Reply-To: Content-Language: en-US X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:181589 Archived-At: This is a multi-part message in MIME format. --------------05307B20715A0076A57CEA31 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi! On 26.05.2020 17:53, Stefan Monnier wrote: >> But really: now we have deadlock too? I just want to solve this >> problem: please let's commit something, and move on to the next bug. > Can you use the sample `eldoc-future-*` code I sent earlier? How about the attached file for a rough, but a largely feature complete first version of futures? To remind from previous discussions, we wanted futures: - To be cancelable, so that the issuer could abort their calculations, if they so desire. - Force-able, meaning the consumer should be able to "realize" the future synchronously, with the future's creator being able to support their, most optimal, version of that logic. The default needs to be useful and reliable enough, though, that callers could use it in 99% of cases anyway. The error callback probably wasn't mentioned, but it seems logical to have it anyway. For the first two features, I also considered using cl-generic, but result might turn out to be clunkier, and we need overridability only for two of these functions. But suggestions welcome. TBD: - Probably rename to "promises" in the end. - It would be nice to have a certain degree of compatibility with Christopher Wellons's emacs-aio, so that its promises could be accepted by code that expects "our" futures/promises. Not sure if we can do that without making the API more complex (aio-resolve's signature comes to mind), or if we adopt its approach, importing the package wholesale might make more sense. --------------05307B20715A0076A57CEA31 Content-Type: text/x-emacs-lisp; charset=UTF-8; name="future.el" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="future.el" ;;; future.el --- Futures, a concurrency primitive -*- lexical-binding: t; -*- ;; Copyright (C) 2020 Dmitry Gutov ;; Author: Dmitry Gutov ;; Keywords: lisp ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; ;;; Code: (require 'cl-lib) (cl-defstruct (future (:conc-name future--) (:constructor future-make (&key force-fn cancel-fn))) "This structure represents a \"future\" value." value error (status 'pending) (force-fn #'future-force--apo) (cancel-fn #'ignore) callback errback) (defun future-force (f) (funcall (future--force-fn f))) (defun future-force--apo (f) (while (eq (future--status f) 'pending) (accept-process-output nil 0.05))) (defun future-cancel (f) (when (eq (future--status f) 'pending) (setf (future--status f) 'canceled) (funcall (future--cancel-fn f)))) (defun future-set (f v) ;; FIXME: Probably shouldn't error on 'canceled'. (cl-assert (eq (future--status f) 'pending)) (setf (future--value f) v (future--status f) 'success) (when (future--callback f) (funcall (future--callback f) v))) (defun future-error (f e) ;; FIXME: Probably shouldn't error on 'canceled'. (cl-assert (eq (future--status f) 'pending)) (setf (future--error f) e (future--status f) 'error) (when (future--errback f) (funcall (future--errback f) e))) ;; Or we can make these both lists of functions... (defun future-set-callback (f c) (cl-assert (null (future--callback f))) (setf (future--callback f) c) (when (eq (future--status f) 'success) (funcall c (future--value f)))) ;; ...and rename to -add-callback/-add-errback. (defun future-set-errback (f c) (cl-assert (null (future--errback f))) (setf (future--errback f) c) (when (eq (future--status f) 'error) (funcall c (future--error f)))) (provide 'future) ;;; future.el ends here --------------05307B20715A0076A57CEA31--