use async to detect when loop in complete