From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Christopher Allan Webber Newsgroups: gmane.emacs.devel Subject: Re: async.el: A simple asynchronous framework for Emacs Date: Tue, 19 Jun 2012 16:38:44 -0500 Message-ID: <87mx3z2d97.fsf@grumps.lan> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1340141777 10887 80.91.229.3 (19 Jun 2012 21:36:17 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 19 Jun 2012 21:36:17 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Jun 19 23:36:16 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Sh65v-0003nl-Vs for ged-emacs-devel@m.gmane.org; Tue, 19 Jun 2012 23:36:16 +0200 Original-Received: from localhost ([::1]:45089 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sh65v-0006nx-TY for ged-emacs-devel@m.gmane.org; Tue, 19 Jun 2012 17:36:15 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sh65t-0006mM-30 for emacs-devel@gnu.org; Tue, 19 Jun 2012 17:36:14 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sh65q-0001Hn-HR for emacs-devel@gnu.org; Tue, 19 Jun 2012 17:36:12 -0400 Original-Received: from li424-160.members.linode.com ([50.116.34.160]:48856 helo=dustycloud.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sh65q-0001HV-De for emacs-devel@gnu.org; Tue, 19 Jun 2012 17:36:10 -0400 Original-Received: from grumps.lan (localhost [127.0.0.1]) by dustycloud.org (Postfix) with ESMTP id 54DB126CEB for ; Tue, 19 Jun 2012 17:36:08 -0400 (EDT) In-Reply-To: (John Wiegley's message of "Mon, 18 Jun 2012 21:51:31 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 50.116.34.160 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 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.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:151034 Archived-At: 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 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 :)