Function flattenAsync