Open ceremcem opened 4 years ago
FYI, there's no child process involved. lsc
evaluates your code in its own process. If you want this behavior, you can modify your own script to cancel any scheduled work whenever the top level runs again, as long as you store the necessary IDs or callbacks on the global object and not just in a variable.
If you want this behavior,
FYI: Currently I'm starting LiveScript files via the following Bash script:
#!/bin/bash
watch=
if [[ "$1" = "-w" ]]; then
echo "Watch mode enabled."
watch=true
shift
fi
lsFile="$1"
shift
if [[ -z $watch ]]; then
lsc $lsFile "$@"
else
LTIME=
CMD_PID=
cleanup(){
[[ -n $CMD_PID ]] && kill $CMD_PID
}
trap cleanup EXIT
while :; do
ATIME=`stat -c %Z "$lsFile"`
if [[ "$ATIME" != "$LTIME" ]]; then
if [[ -n $CMD_PID ]]; then
echo "---------------------------------------"
echo "| Restarting... |"
echo "---------------------------------------"
kill $CMD_PID
fi
lsc $lsFile "$@" &
CMD_PID=$!
LTIME=$ATIME
fi
sleep 2
done
fi
Which:
@ceremcem watch processes are quite complicated, unfortunately.
My humble advice to use https://github.com/remy/nodemon.
When source script is changed, kills the previous process and starts another one.
Even nodemon
struggles here, so something like livescript
would definitely not be expected to handle the issue.
The only lib that fixes many of the cross-platform problem here is https://github.com/paulmillr/chokidar.
but you still have to manually tweak the options for different OS and hardware.
Good Luck !
The
--watch
switch in CLI is intended for progressive script compilation and works well for that case. This feature is very useful while developing a long-running server side script as well.However, it behaves unexpected when executing a long-running script, like with
lsc -w myscript.ls
. That starts just another instance before killing previous instance.Expected
lsc -w
should kill previous instance (if exists) and then start the new process.Test case
Output is: