all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* async.el: A simple asynchronous framework for Emacs
@ 2012-06-19  2:51 John Wiegley
  2012-06-19  5:11 ` Thien-Thi Nguyen
                   ` (3 more replies)
  0 siblings, 4 replies; 24+ messages in thread
From: John Wiegley @ 2012-06-19  2:51 UTC (permalink / raw)
  To: emacs-devel

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 :)



^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2012-06-26  9:41 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-19  2:51 async.el: A simple asynchronous framework for Emacs John Wiegley
2012-06-19  5:11 ` Thien-Thi Nguyen
2012-06-19  5:36   ` John Wiegley
2012-06-19 13:29 ` Stefan Monnier
2012-06-19 20:44   ` John Wiegley
2012-06-19 21:46     ` Stefan Monnier
2012-06-20  0:20       ` John Wiegley
2012-06-20  0:53         ` John Wiegley
2012-06-20  5:34       ` John Wiegley
2012-06-20  7:24         ` SAKURAI Masashi
2012-06-20  7:52           ` John Wiegley
2012-06-20  8:13             ` John Wiegley
2012-06-20  8:24               ` John Wiegley
2012-06-20  9:32               ` SAKURAI Masashi
2012-06-20 20:36         ` Thien-Thi Nguyen
2012-06-20 23:52           ` John Wiegley
2012-06-21 13:17             ` Thien-Thi Nguyen
2012-06-22 16:01               ` Le Wang
2012-06-22 20:07                 ` Thien-Thi Nguyen
2012-06-24  9:30                   ` Chong Yidong
2012-06-19 21:38 ` Christopher Allan Webber
2012-06-21  8:31 ` Thierry Volpiatto
     [not found]   ` <m2lijg8ibx.fsf@vulcan.local.i-did-not-set--mail-host-address--so-tickle-me>
     [not found]     ` <87a9zv1fw4.fsf@gmail.com>
     [not found]       ` <m2ehp73t8o.fsf@vulcan.local.i-did-not-set--mail-host-address--so-tickle-me>
     [not found]         ` <871ul63yky.fsf@gmail.com>
     [not found]           ` <m2zk7tzr5e.fsf@vulcan.local.i-did-not-set--mail-host-address--so-tickle-me>
     [not found]             ` <87395lyam9.fsf@gmail.com>
2012-06-26  0:05               ` John Wiegley
2012-06-26  9:41                 ` Thierry Volpiatto

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.