From f58742d7e03a6377fa02b6a5403f651ccabdde70 Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Mon, 26 Sep 2022 07:29:19 -0400 Subject: [PATCH] examples: cleanup: use coproc --- README.md | 27 ++++++--------------------- examples/bot.sh | 22 +++------------------- 2 files changed, 9 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index e2be1fd..18e4530 100644 --- a/README.md +++ b/README.md @@ -186,20 +186,6 @@ set -o errexit set -o nounset set -o pipefail -trap cleanup EXIT - -TMPDIR=$(mktemp -d) - -in="$TMPDIR/stdin" -out="$TMPDIR/stdout" - -mkfifo "$in" -mkfifo "$out" - -cleanup() { - rm -rf "$TMPDIR" -} - decode() { printf '%b' "${1//%/\\x}" } @@ -240,11 +226,11 @@ bot() { echo "$MSG" ;; esac - done <"$out" + done } -bot >"$in" & -xmppipe "$@" <"$in" >"$out" +coproc bot +xmppipe "$@" <&"${COPROC[0]}" >&"${COPROC[1]}" ~~~ ## Sending Notifications/Alerts @@ -287,12 +273,11 @@ This example will stream events from a query to an XMPP MUC using are written to a named pipe to avoid buffering. ~~~ shell -mkfifo riemann -curl -s --get --data subscribe=true \ +coproc curl -s --get --data subscribe=true \ --data-urlencode 'query=(service ~= "^example")' \ - http://example.com:80/index riemann & + http://example.com:80/index "$in" & -xmppipe "$@" <"$in" >"$out" +coproc bot +xmppipe "$@" <&"${COPROC[0]}" >&"${COPROC[1]}"