Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Cool presentation of Asynchronicity, a recent buzz-word in Zsh topic
- X-seq: zsh-users 23716
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Cool presentation of Asynchronicity, a recent buzz-word in Zsh topic
- Date: Wed, 24 Oct 2018 10:43:45 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to :content-transfer-encoding; bh=lYddiUZDnakIccRaU3ClnVURQ3hkgRIZM2KCdWziR0Q=; b=nkDhJYdL5jc5E+5rhiYZ+FYDYODH3KjYBU6NefE5PsbxjSUHWsBwCwoq6lWfTcQ8dM 0xpSX98JNiFXTAvvfP7MPocZG4XUhkSwlqC1zETGOZ/9d/wMSaQ8aNFefylRDzA/0B7k y2Z7tQHKcfCiDm4AKrUFSz/IbyjwrMxcIe1KE4AF60bEDhEnqlGl7Aa/arof5Q2bcEZG 32uEBU7zdhA7gf5tkZUhYmpS7GiJOTLabtuI2H00m3+G5XA2nVc3Xx6046T1VkBLJKph xw/DjnzjaJqXNxOnDBDexmOfVqEJVHWqhD5uUrjvJMFEGpjZXPauRCnO53LQix2S8zZ2 SRGw==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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