Add wait function for threaded calls