Wait for task to complete