Wait for the producer thread to finish before destroying the encoded stream
Otherwise we end up crashing because the thread is still trying to access things that are now gone.
Otherwise we end up crashing because the thread is still trying to access things that are now gone.