zsh-users
 help / color / mirror / code / Atom feed
From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: Zsh Users <zsh-users@zsh.org>
Subject: Cool presentation of Asynchronicity, a recent buzz-word in Zsh topic
Date: Wed, 24 Oct 2018 10:43:45 +0200	[thread overview]
Message-ID: <CAKc7PVDuwHwvoqLeF=-HW2yis7C8YabfAsTSyVuG_mUwug7R8A@mail.gmail.com> (raw)

Hello,
from some time (1 or 1.5 years?) there's the topic of async-operation
in Zsh plugins. There's the plugin mafredri/zsh-async, which uses
module zsh/zpty to run background task and return via zle -F handler.

I've discovered that <( ) is a good method to run background task. It
is simpler than using an API of a plugin and very simple in general.
Three lines of code are needed to run a task in background:

            exec {ZTSFD}< <(LANG=C sleep 0.3; print -r -- $CUR_SECONDS)
            command true # workaround Zsh bug
            zle -F -w "$ZTSFD" zts_postponed_redisplay

After that, after 300 ms, zts_postponed_redisplay() will be called (if
the command line is unused, free), with stdin plugged so that it can
read $CUR_SECONDS. There's Zsh bug, and a risk of segfaults, I wasn't
able to track this fully (only found the workaround), but I've made a
plugin that makes intense use of <( ), and here's the result (the
presentation of async-work) – smooth operation without problems:

https://asciinema.org/a/207856

-- 
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org

                 reply	other threads:[~2018-10-24  8:44 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

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

  git send-email \
    --in-reply-to='CAKc7PVDuwHwvoqLeF=-HW2yis7C8YabfAsTSyVuG_mUwug7R8A@mail.gmail.com' \
    --to=sgniazdowski@gmail.com \
    --cc=zsh-users@zsh.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.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).