mafredri / zsh-async

Because your terminal should be able to perform tasks asynchronously without external tools!
MIT License
766 stars 34 forks source link

Tests pass, but example script never concludes #36

Closed jubishop closed 4 years ago

jubishop commented 4 years ago

I've removed my .zshrc entirely to ensure I have nothing conflicting or causing problems.

Then I:

git clone https://github.com/mafredri/zsh-async.git
cd zsh-async
./test.zsh

and that prints ok ./async_test.zsh 5.426s

but if I copy the entirety of the example script into example.zsh then:

source example.zsh

it just prints "Waiting..." endlessly and never completes. When I terminate it with ctrl-C at that point it actually prints

print 0 hello 0.0011861324 1
sleep 0 0.3029172421 0

but if I don't terminate it, those items never print.

I've tried many tests of my own and see the same results, just figured I'd offer as a repo the example itself.

I'm using zsh 5.7.1, all other aspects of zsh seem to work fine for me.

thanks for any help!

jubishop commented 4 years ago

ok mb it works if i do ./example.zsh instead of source example.zsh it works! can you maybe enlighten me on what the difference is here? i'm used to using them interchnageably...

mafredri commented 4 years ago

Hey @jubishop,

there's quite a significant difference between the two, actually. In the first case ./example.zsh the script is run, think of it like running a completely separate program. In the second, using source you're also running the script but you're running it as part of your current shell, and any changes it does will also become part of your shell. There's also other changes in behavior between run and source, for example, if you source a script that says exit 0 it will exit your whole shell and you have to start a new one, vs if you run that same script, it will only exit the script and return to your shell.

The example is meant to be run as a separate program so that it can make changes to its own environment without affecting your shell, this is why source won't work.