Run async function in a loop