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

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

    // The main thread should update its menu

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