How to create Multi Producer-Single Consumer concurrency
adnan338
relay.dev.adnan at protonmail.com
Fri Jun 12 22:02:48 UTC 2020
I have a list of files to download from the internet. Each of
those downloads are a time consuming task.
What I want to do is download them concurrently and when each of
those downloads finish, I want to activate something in my main
thread, which will update a progressbar in the GUI thread.
So there are multiple "download finished" message producers, and
one consumer of those messages. Furthermore, that producer has a
callback that triggers an UI object.
For example,
auto list = [...]; // list of URLs
auto downloadableItems = list.length;
__gshared int downloaded = 0;
auto progressBar = // a gtk progressbar;
How should I proceed? I can do a parallel foreach and call
download() on each of the URL and update `downloaded`, but I
don't know how to listen to `downloaded` when it gets updated so
I can make changes in `progressBar`
Not that my UI library is not thread safe and I cannot access UI
object from different threads.
More information about the Digitalmars-d-learn
mailing list