Any strategy / shard suggestion for how to cleanly log output from multiple fibers? Ideally, I’d love to have the output on the command line look something like this:
Fiber 1 - Step 1 complete....Step 2 complete.....done.
Fiber 2 - Step 1 complete....Step 2 complete.....done.
Fiber 3 - Step 1 complete....Step 2 complete.....done.
The key would be to have each line update as its respective Fiber completes the appropriate steps.
Thanks in advance!
Hey Noah, an approach I like is one where
worker fibers publish updates to a channel every time they start/complete a task,
- a separate fiber (let’s call it state keeper) consumes from it, updates the state of the program and triggers a UI update in a thread-safe way.
If the terminal is your UI, then you might want to look into something like ncurses or Crysterm to make your text output more pleasant - and avoid having to clear the screen on each update.
For an actual example, I took the same approach when I wrote my torrent client - check out the UI folder.
Hope some of this helps!
Lorenzo THANK YOU! This is exactly the kind of guidance I was looking for. Your example UI code is perfect and this is a huge help. I’ll report back.