zsh-users
 help / color / mirror / code / Atom feed
* Cool presentation of Asynchronicity, a recent buzz-word in Zsh topic
@ 2018-10-24  8:43 Sebastian Gniazdowski
  0 siblings, 0 replies; only message in thread
From: Sebastian Gniazdowski @ 2018-10-24  8:43 UTC (permalink / raw)
  To: Zsh Users

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-10-24  8:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-24  8:43 Cool presentation of Asynchronicity, a recent buzz-word in Zsh topic Sebastian Gniazdowski

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