View Single Post
Old 03-19-2017, 04:04 PM   #2
Human being with feelings
Xenakios's Avatar
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 7,344

Originally Posted by SpiderFox View Post

std::future<std::vector<Project>> f = std::async(std::launch::async, &ProjectsController::getProjects, &pc);

How can I make it load in the background?
You have to store the returned future from std::async somewhere else than a local variable. The destructor of the future variable (or I think in your case running the isReady function) will block the execution of the current thread, negating the use of the async operation if the future is a local variable in a function. So make it a class member variable or a global variable instead. You will of course have to do the ready checking somewhere else too, taking care you don't block the GUI thread from returning to the event loop as soon as possible. (Maybe you could use a Juce timer that periodically checks if the future is ready or not, but also there you have to use do the check very quickly and not wait for the future.)

This problem is universal to GUI frameworks, not specific to JUCE. You should not do any operations that block the execution of the GUI thread for a long time.
For info on SWS Reaper extension plugin (including Xenakios' previous extension/actions) :
Xenakios blog (about HourGlass, Paul(X)Stretch and λ) :
Xenakios is online now   Reply With Quote