AudioDeviceManager close/restart need to wait?

I'm writing a pitch detection app and allowing the user to switch between methods, one of which uses a different library to the others, and also set other things that require re-initialisating e.g. buffer size. 

When the user selects a different method or value,  the component calls deviceManager.closeAudioDevice() followed by the constructor (of the class inheriting AudioIODeviceCallback) with new settings, followed by deviceManager.restartLastAudioDevice(). 

Currently it seems the audioDeviceIOCallback function is still getting called before things are reinitialised

I assume I need to use audioDeviceStopped(), so I can safely reinitialise things. . Just not sure how to arrange the code, so it waits before doing stuff.

No.. it'll definitely stop calling the audio callback before closeAudioDevice() returns.

Ok, thanks. I thnk the problem I've been having is due to the ValueTree's properties getting changed while the audio callback is still running, before the valueTreePropertyChanged function has a chance to stop it - at least thats how i've had it arranged. 

I'm in the process of rearranging the code so that the closeAudioDevice() function is called when the user switches to the settings view, and restarted when switching back to the main GUI. Save some CPU cycles too... otherwise perhaps I need to to close it using the focusGained() function on the relevant property components.