return EnvFuture from flush_all
use derivative::Derivative;
use enclose::enclose;
-use futures::{future, FutureExt};
+use futures::{future, FutureExt, TryFutureExt};
use serde::Serialize;
use std::collections::VecDeque;
use std::marker::PhantomData;
@@ -117,7 +117,7 @@ impl<E: Env + 'static> Analytics<E> {
.await;
};
}
- pub async fn flush_all(&self) {
+ pub fn flush_all(&self) -> EnvFuture<()> {
let mut state = self.state.lock().expect("analytics state lock failed");
state.pending = None;
let batches = state.queue.drain(..).collect::<Vec<_>>();
@@ -127,7 +127,9 @@ impl<E: Env + 'static> Analytics<E> {
.iter()
.map(|batch| send_events_batch_to_api::<E>(&batch)),
)
- .await;
+ .map(|results| results.into_iter().collect::<Result<Vec<_>, _>>())
+ .map_ok(|_| ())
+ .boxed_local()
}
}
