fix async flush function