Give response back to the main thread on api calls

fix #4337