Skip to content

Commit

Permalink
fix kill logic for SSE
Browse files Browse the repository at this point in the history
  • Loading branch information
cgsdev0 committed Aug 22, 2023
1 parent 359c80f commit 03cffa0
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,16 @@ writeHttpResponse() {
header Content-Type "text/event-stream"
end_headers
output() {
killthehmr() {
kill "$HMR_PID" &> /dev/null
wait "$HMR_PID" &> /dev/null
exit 0
}
trap 'killthehmr' TERM
while true; do
inotifywait -e MODIFY -r pages static &> /dev/null
inotifywait -e MODIFY -r pages static &> /dev/null &
HMR_PID=$!
wait "$HMR_PID" &> /dev/null
event "reload"
done
}
Expand All @@ -381,8 +389,8 @@ writeHttpResponse() {
:
done

kill -9 $PID &>/dev/null
wait $PID 2>/dev/null
kill $PID &>/dev/null
wait $PID &>/dev/null

return
elif [[ -z "$ROUTE_SCRIPT" ]]; then
Expand All @@ -405,8 +413,16 @@ writeHttpResponse() {
fi
SUB_FD=$(subscribe "$TOPIC")
output() {
killthecat() {
kill "$CAT_PID" &> /dev/null
wait "$CAT_PID" &> /dev/null
exit 0
}
trap 'killthecat' TERM
while true; do
cat "$SUB_FD"
cat "$SUB_FD" &
CAT_PID=$!
wait "$CAT_PID" &> /dev/null
done
}
output &
Expand All @@ -418,8 +434,8 @@ writeHttpResponse() {
:
done

kill -9 $PID &>/dev/null
wait $PID 2>/dev/null
kill "$PID" &>/dev/null
wait "$PID" &>/dev/null

unsubscribe "$SUB_FD"
[[ $(type -t on_close) == function ]] && on_close 1>&2
Expand Down

0 comments on commit 03cffa0

Please sign in to comment.