From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Zhu Zihao Newsgroups: gmane.emacs.devel Subject: Re: "Asynchronous Requests from Emacs Dynamic Modules" Date: Sat, 31 Oct 2020 11:18:43 +0800 Message-ID: <86y2jn9j70.fsf@163.com> References: <86imarfldb.fsf@akirakyle.com> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="1114"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.13; emacs 27.1 Cc: emacs-devel@gnu.org To: Akira Kyle Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Sat Oct 31 04:20:06 2020 Return-path: Envelope-to: ged-emacs-devel@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 1kYhQz-0000C0-KW for ged-emacs-devel@m.gmane-mx.org; Sat, 31 Oct 2020 04:20:05 +0100 Original-Received: from localhost ([::1]:41738 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kYhQu-0005MJ-JQ for ged-emacs-devel@m.gmane-mx.org; Fri, 30 Oct 2020 23:20:04 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kYhQA-0004vd-LD for emacs-devel@gnu.org; Fri, 30 Oct 2020 23:19:17 -0400 Original-Received: from mail-m975.mail.163.com ([123.126.97.5]:52954) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kYhQ5-0006x5-94 for emacs-devel@gnu.org; Fri, 30 Oct 2020 23:19:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-ID:MIME-Version; bh=RFSzZ crwAxi7Bneq7M8Fdm2HuR1n/1WJtpH7z0YX4Fo=; b=OGczmSMsP1aAxLlEv2lP6 whJ8jlAKUJ70AmVGVbw/eabmaTINGoTghC/8gdzuGqTZHP9w05+7yCiWDvkv5aX/ rFl7oaIDxKz+FV0VTlU18kB9dz3g04qgOt6Gg7GEaLim6pDwYPjUGVDqB8CTeueo L9LuMTbFRFSdmTbNrri3Wo= Original-Received: from asus-laptop (unknown [27.39.89.72]) by smtp5 (Coremail) with SMTP id HdxpCgDnh8Ga15xfAZjHBw--.12S2; Sat, 31 Oct 2020 11:18:51 +0800 (CST) In-reply-to: <86imarfldb.fsf@akirakyle.com> X-CM-TRANSID: HdxpCgDnh8Ga15xfAZjHBw--.12S2 X-Coremail-Antispam: 1Uf129KBjvJXoW7KF4kZFW8GF17Jr4DXFyDGFg_yoW8CFWkp3 y8Gry5CFZYqr4DArW8Jw48XFySkrZ7XwsIgF98G3y3Za13GFZavF10yayYvrWxuFn3XryU JFy5ur1DGryqy3DanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0zRNVysUUUUU= X-Originating-IP: [27.39.89.72] X-CM-SenderInfo: pdoosuxxwbztlvw6il2tof0z/1tbiFBvOr1aD7t5UdQAAsq Received-SPF: pass client-ip=123.126.97.5; envelope-from=all_but_last@163.com; helo=mail-m975.mail.163.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/10/30 23:18:56 X-ACL-Warn: Detected OS = Linux 3.1-3.10 X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 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-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:258569 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable What about callbacks? You can pass a Lisp closure to module and call the closure from module. You may also want something like "Promise" in JavaScript to make it sweet Emacs Lisp Promise/A+ Implementation: https://github.com/chuntaro/emacs-pro= mise=20 Akira Kyle writes: > I'm trying to use Emacs' Dynamic Modules in an asynchronous setting where= C > module functions run in a separate thread from Emacs' main thread which is > responsible for calling into the module functions. The natural problem th= en is > how to notify Emacs when one wants to retrieve the result of the asynchro= nous=20 > operation from some lisp. Since the module docs explicitly say that module > functions "may only interact with Emacs from Lisp interpreter threads (in= cluding > the main thread) created by Emacs", it is not possible then for a separate > module thread to interact with Emacs in an unprompted way through the mod= ule > interface [1]. > > This blog post [2] has a solution to this problem by sending SIGUSR1 to E= macs, > but that feels a bit hackish and forces one to do more work to manage all= the > different possible module threads and events that one may want to signal = to > Emacs. I suppose one could also conceivably also use Emacs' dbus support = but > that still feels clunky. Maybe its possible it's possible to use Emacs li= sp's=20 > threads [2] to solve this but it's not clear to me how to go about doing = so and > I haven't found anyone that has done so. > > Does anyone know of the best way to handle this? Perhaps the module inter= face > should be expanded to handle this situation? > > [1] > https://www.gnu.org/software/emacs/manual/html_node/elisp/Module-Function= s.html#Module-Functions > [2] > https://www.gnu.org/software/emacs/manual/html_node/elisp/Threads.html#Th= reads > [3] https://nullprogram.com/blog/2017/02/14/ =2D-=20 Retrieve my PGP public key: https://meta.sr.ht/~citreu.pgp Zihao --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQFJBAEBCAAzFiEE7NCVzXX6efyusptG1SOVn+xGFqYFAl+c15MVHGFsbF9idXRf bGFzdEAxNjMuY29tAAoJENUjlZ/sRham138H/34YYB/LxwPgmKSjBOk92HWgIfis C3x+sbjtJQd4WPSS3ld8iMq0Y27OqdVApGHk7eOmwcGPYHjq6kX/gcejw4+ST7uZ ZnoJCSHFVWan9A6tPCzuyUsjKDpjAtzrZsiINy7FtsUWJzH6D8WizTKCfHghyLmD v7Wrsm0M/7NKpbaymwEXRKtqJAraLqHjwowS2DO9FREnqPORX1Miof3XIfhgKBFV BmVA+DY/Dwu4iRqzukjjC6rNQA8A+cUz0Ce1sHiTcBsealVjUUfgmPc/rz/GI113 aFLFwCePXA/jU0rszYK3eX9dxHG1+IKCi2H8fVyqCkCII4JjHxpXkt3YAYU= =kkVF -----END PGP SIGNATURE----- --=-=-=--