emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: async.el: A simple asynchronous framework for Emacs


From: Christopher Allan Webber
Subject: Re: async.el: A simple asynchronous framework for Emacs
Date: Tue, 19 Jun 2012 16:38:44 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

I just wanted to jump in and say that this seems like a really exciting
future.  I can already imagine a lot of exciting things that could make
use of it without having any crazy complexity in threading and locking
and etc in emacs.

I hope it happens!

 - Chris

John Wiegley <address@hidden> writes:

> Hello,
>
> I think we've all wanted threading and asynchronicity in Emacs for some time
> now (Gnus, anyone?), and there have been many attempts to provide it.  I
> propose a module for inclusion in Emacs, async.el, which offers a very ease to
> use model for asynchronicity, without the need for any threading (and its
> attendant complexities).  It should work on every platform that supports
> asynchronous processes using `start-process'.
>
> The whole interface is two functions: `async-start' and `async-get' (of which
> the latter is optional).  Here is the basic form of use:
>
>     (async-start (lambda () ...)
>                  'function-to-call-when-done)
>
> This will execute the lambda (which must *not* be byte-compiled -- in other
> words, don't use `function' or #') in a child Emacs asynchronously.  When it's
> done, the return value is passed to `function-to-call-when-done' as an
> argument.  (If you don't care about the return value, pass the `ignore' symbol
> as the second argument).
>
> If you pass no second argument, a future is returned.  You can later call
> `async-get' on this future to obtain the value, blocking if necessary.
>
> That's it.  All you need to do asynchronous computation within Emacs.
>
> Since it's likely that you'll want the child Emacs to heavy lifting based on
> the parent Emacs' configuration, you can use `async-inject-environment' to
> pass variable definitions across the process boundary:
>
>     (async-start (lambda ()
>                    (require 'some-module)
>                    (async-inject-environment "\\`some-module-")
>                    ...))
>
> The variable definitions from the module "some-module" will be passed into the
> child.
>
> Using these facilities, here's all it takes to send e-mail asynchronously with
> smtpmail.el:
>
>     (defun async-smtpmail-send-it ()
>       (async-start
>        `(lambda ()
>           (require 'smtpmail)
>           (with-temp-buffer
>             (insert ,(buffer-substring-no-properties (point-min) (point-max)))
>             ;; Pass in the variable environment for smtpmail
>             ,(async-inject-environment 
> "\\`\\(smtpmail\\|\\(user-\\)?mail\\)-")
>             (smtpmail-send-it)))
>        'ignore))
>
> I've also written dired-async.el, which performs copies, moves and deletes
> asynchronously.  It works great with Tramp.
>
> The files are hosted on GitHub presently:
>
>     https://github.com/jwiegley/emacs-async
>
> One thing I would love to do is to work with the authors of other modules --
> such as one of my all-time favorites, Gnus -- to see how a facility like this
> can help improve user experience.
>
> Comments welcome,
>   John
>
> p.s. This e-mail sent asynchronously with smtpmail.el :)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]