Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Cool presentation of Asynchronicity, a recent buzz-word in Zsh topic



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



Messages sorted by: Reverse Date, Date, Thread, Author