Block mouse events until thread finished

So I am working on a Sound Map, where I am loading the wav files into Sound objects on a background thread to not block the loading and painting of the corresponding SoundComponent object. However the sound component’s mouseEnter function triggers the playback of the transportSource which is obviously giving me an error when the corresponding file hasn’t yet been loaded in the background thread. How can I block the triggering and wait for the thread to load all samples and exit?

I have dealt something like this. I have an atomic refresh state variable which tracks the background thread loading. The class looks like,

enum class TreeState
{
    // The state is just been init
    init,

    // Not doing any refreshing.
    refreshComplete, 
    
    // The background thread can start refreshing
    shouldRefresh, 
    
    // The background thread is refreshing
    refreshing, 

    // The main thread should update its menu
    exchangeTrees 
};

Probably in your case, you can set up a communication in a similar way and wait if the background refresh is still happening.