javascript wait for result of async function