unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Zhu Zihao <all_but_last@163.com>
To: Akira Kyle <ak@akirakyle.com>
Cc: emacs-devel@gnu.org
Subject: Re: "Asynchronous Requests from Emacs Dynamic Modules"
Date: Sat, 31 Oct 2020 11:18:43 +0800	[thread overview]
Message-ID: <86y2jn9j70.fsf@163.com> (raw)
In-Reply-To: <86imarfldb.fsf@akirakyle.com>

[-- Attachment #1: Type: text/plain, Size: 1931 bytes --]


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-promise 

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 then is
> how to notify Emacs when one wants to retrieve the result of the asynchronous 
> operation from some lisp. Since the module docs explicitly say that module
> functions "may only interact with Emacs from Lisp interpreter threads (including
> 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 module
> interface [1].
>
> This blog post [2] has a solution to this problem by sending SIGUSR1 to Emacs,
> 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 lisp's 
> 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 interface
> should be expanded to handle this situation?
>
> [1]
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Module-Functions.html#Module-Functions
> [2]
> https://www.gnu.org/software/emacs/manual/html_node/elisp/Threads.html#Threads
> [3] https://nullprogram.com/blog/2017/02/14/


-- 
Retrieve my PGP public key: https://meta.sr.ht/~citreu.pgp

Zihao

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 515 bytes --]

  parent reply	other threads:[~2020-10-31  3:18 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-30 21:35 "Asynchronous Requests from Emacs Dynamic Modules" Akira Kyle
2020-10-30 22:39 ` Stefan Monnier
2020-10-31  3:18 ` Zhu Zihao [this message]
2020-10-31  7:45   ` Eli Zaretskii
2020-10-31  8:02     ` yyoncho
2020-10-31  9:13       ` Eli Zaretskii
2020-10-31  9:45         ` yyoncho
2020-10-31 10:43           ` Eli Zaretskii
2020-10-31 19:25             ` Akira Kyle
2020-10-31 20:18               ` Eli Zaretskii
2020-11-01  0:14                 ` Akira Kyle
2020-11-01 18:28                   ` Eli Zaretskii
2020-11-01 20:15                     ` Akira Kyle
2020-11-01 20:51                       ` async-await (was: Re: "Asynchronous Requests from Emacs Dynamic Modules") Philipp Stephani
2020-11-02 15:22                       ` "Asynchronous Requests from Emacs Dynamic Modules" Eli Zaretskii
2020-10-31  7:36 ` Philipp Stephani
2020-10-31 12:49   ` Stefan Monnier
2020-11-01 20:18     ` Akira Kyle
2020-11-01 20:32       ` Philipp Stephani
2020-11-20 15:54     ` Zhu Zihao
2020-11-20 16:04       ` Robert Pluim

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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=86y2jn9j70.fsf@163.com \
    --to=all_but_last@163.com \
    --cc=ak@akirakyle.com \
    --cc=emacs-devel@gnu.org \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).