unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Amirouche Boubekki <amirouche.boubekki@gmail.com>
To: Chris Vine <chris@cvine.freeserve.co.uk>, guile-user@gnu.org
Subject: Re: Potluck - thread safe event loop with await semantics
Date: Tue, 01 Mar 2016 20:39:30 +0000	[thread overview]
Message-ID: <CAL7_Mo9J1GyHJPvg4H2WhUz+DS4iCK_L8otQ9KWEGY-WL3owvA@mail.gmail.com> (raw)
In-Reply-To: <20160222174056.2091d806@dell.homenet>

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

Héllo

On Mon, Feb 22, 2016 at 6:47 PM Chris Vine <chris@cvine.freeserve.co.uk>
wrote:

> On Mon, 22 Feb 2016 13:01:01 +0100
> ludo@gnu.org (Ludovic Courtès) wrote:
> > Chris Vine <chris@cvine.freeserve.co.uk> skribis:
> >
> > > It features an a-sync procedure (in coroutines.scm) which can be
> > > used to provide await semantics on asynchronous code (so as to
> > > remedy inversion of control), and will work with callbacks for any
> > > event loop, including the glib event loop wrapped by guile-gnome.
> > > More to the point, it also provides a thread safe event loop for
> > > guile (event-loop.scm) with support for watches on ports/file
> > > descriptors, and now supports proper timeouts, and permits events
> > > to be posted by other tasks.  This includes tasks running on other
> > > threads, for which there is a helper procedure
> > > a-sync-run-task-in-thread.
> >
> > Interesting.  Have you tried to integrate it with one of the
> > object-oriented event loops like in GLib?  (Back in the day I thinking
> > about something like that to avoid the callback hell in Guile-Avahi.)
> >
> > Thanks for the tasty dish!  :-)
> >
> > Ludo’.
>
> This is an example of how you might use a-sync with guile-gnome:
>
> ;;;;;;;;
>
> (use-modules (gnome glib) (coroutines))
>
> (define main-loop (g-main-loop-new #f #f))
>
> (a-sync (lambda (await resume)
>          ;; launch asynchronous task
>          (g-idle-add (lambda ()
>                        (display "In first async callback\n")
>                        (resume "Hello via async\n")
>                        #f))
>          (display "About to make first wait\n")
>          (display (string-append "Back in waitable procedure, and the
> callback says: " (await)))
>
>          ;; launch another asynchronous task
>          (g-idle-add (lambda ()
>                        (display "In second async callback\n")
>                        (g-main-loop-quit main-loop)
>                        (resume)
>                        #f))
>          (display "About to make second wait\n")
>          (await)
>          (display "Quitting\n")))
>
> (display "Starting main loop\n")
> (g-main-loop-run main-loop)
>
> ;;;;;;;;
>

It's very different from asyncio's await. The kind of coroutine you use are
more general than Python's coroutine.

The code would be nicer (and look more like asyncio) if it looked like this
snippet https://friendpaste.com/6Q8HZw1SMOhAVCyfY2dAG7

Basically await procedure takes another procedure that implement the resume
behavior. In a sens `(await idle)` is similar to some kind of `(await sleep
5)` implementation. Not sure this last sentence make really sens to you.

Happy hacking!

[-- Attachment #2: Type: text/html, Size: 3680 bytes --]

      parent reply	other threads:[~2016-03-01 20:39 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-16 21:45 Potluck - thread safe event loop with await semantics Chris Vine
2016-02-22 12:01 ` Ludovic Courtès
2016-02-22 16:36   ` Marko Rauhamaa
2016-02-22 17:40   ` Chris Vine
2016-02-22 17:53     ` Thompson, David
2016-02-22 18:12       ` Chris Vine
2016-02-22 19:54         ` Christopher Allan Webber
2016-02-22 20:28     ` David Pirotte
2016-02-23  0:31       ` Chris Vine
2016-02-23  1:30         ` Chris Vine
2016-02-23 19:55           ` David Pirotte
2016-02-23  6:25         ` David Pirotte
2016-02-23 12:09           ` Chris Vine
2016-02-23 16:49             ` Chris Vine
2016-02-25 23:22             ` David Pirotte
2016-02-23  4:58     ` Chris Vine
2016-03-01 20:39     ` Amirouche Boubekki [this message]

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/guile/

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

  git send-email \
    --in-reply-to=CAL7_Mo9J1GyHJPvg4H2WhUz+DS4iCK_L8otQ9KWEGY-WL3owvA@mail.gmail.com \
    --to=amirouche.boubekki@gmail.com \
    --cc=chris@cvine.freeserve.co.uk \
    --cc=guile-user@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.
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).