examples: cleanup: use coproc

master
Michael Santos 2 years ago
parent 11d854f9e7
commit f58742d7e0

@ -186,20 +186,6 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
trap cleanup EXIT
TMPDIR=$(mktemp -d)
in="$TMPDIR/stdin"
out="$TMPDIR/stdout"
mkfifo "$in"
mkfifo "$out"
cleanup() {
rm -rf "$TMPDIR"
}
decode() { decode() {
printf '%b' "${1//%/\\x}" printf '%b' "${1//%/\\x}"
} }
@ -240,11 +226,11 @@ bot() {
echo "$MSG" echo "$MSG"
;; ;;
esac esac
done <"$out" done
} }
bot >"$in" & coproc bot
xmppipe "$@" <"$in" >"$out" xmppipe "$@" <&"${COPROC[0]}" >&"${COPROC[1]}"
~~~ ~~~
## Sending Notifications/Alerts ## 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. are written to a named pipe to avoid buffering.
~~~ shell ~~~ shell
mkfifo riemann coproc curl -s --get --data subscribe=true \
curl -s --get --data subscribe=true \
--data-urlencode 'query=(service ~= "^example")' \ --data-urlencode 'query=(service ~= "^example")' \
http://example.com:80/index </dev/null >riemann & http://example.com:80/index </dev/null
xmppipe --verbose --verbose \ xmppipe --verbose --verbose \
--discard --subject "riemann events" muc <riemann --discard --subject "riemann events" muc <&"${COPROC[0]}"
~~~ ~~~
### Desktop Notifications ### Desktop Notifications

@ -4,26 +4,10 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
trap cleanup 0
BOT_DEBUG=${BOT_DEBUG-""}
if [ "$BOT_DEBUG" ]; then if [ "$BOT_DEBUG" ]; then
set -x set -x
fi fi
TMPDIR=$(mktemp -d)
in="$TMPDIR/stdin"
out="$TMPDIR/stdout"
mkfifo "$in"
mkfifo "$out"
cleanup() {
rm -rf "$TMPDIR"
}
decode() { decode() {
printf '%b' "${1//%/\\x}" printf '%b' "${1//%/\\x}"
} }
@ -73,8 +57,8 @@ bot() {
fi fi
;; ;;
esac esac
done <"$out" done
} }
bot >"$in" & coproc bot
xmppipe "$@" <"$in" >"$out" xmppipe "$@" <&"${COPROC[0]}" >&"${COPROC[1]}"

Loading…
Cancel
Save