woutdp / live_svelte

Svelte inside Phoenix LiveView with seamless end-to-end reactivity
https://hexdocs.pm/live_svelte
MIT License
1.01k stars 37 forks source link

Run setup tasks synchronously #95

Closed tonydangblog closed 7 months ago

tonydangblog commented 7 months ago

Summary

Change LiveSvelte setup tasks to run synchronously.

Reason for change

Currently the setup tasks run asynchronously. However this could lead to jumbled terminal output such as in the following screenshot:

Screenshot 2023-11-23 at 16 51 57

This is not ideal because the user installing live_svelte may miss the prompt for the file overwrite and think that the process just hung. (This is what happened to me and it took a while to figure out what was wrong 😅). Changing the setup tasks to run synchronously will show a clearer output to the user:

Screenshot 2023-11-23 at 17 02 18

woutdp commented 7 months ago

Nice!

Did you look into using Stream.map for this instead? The previous code is slightly more readable but I do like your solution more as it solves a real issue. We might be able to keep the previous code with your fix by using Stream.map. But I'm unsure if that would work, would have to test it myself but since you're already working on it might be faster if you check. If it doesn't work then feel free to just say so and I'll merge :)

tonydangblog commented 7 months ago

I haven't looked at using Stream.map yet, but I can definitely take a look. I'm out the rest of this weekend, but will try it out first chance I get and let you know!

tonydangblog commented 7 months ago

I took another look and realized I was overcomplicating things. The Enum module functions already runs things synchronously so there was no need to use Task.async and Task.await. I refactored the code to be a simple and clear one-liner using Enum.each. Please see the latest commit and lmk if things look better now!

woutdp commented 7 months ago

Nice, even better!