diff --git a/client/src/lib.rs b/client/src/lib.rs index 059048f..3bdecb0 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -144,7 +144,7 @@ impl ClientBuilder { } impl Client { - pub fn push_event(&mut self, event: Event) { + pub fn push(&mut self, event: Event) { let mut guard = self.inner.try_lock().unwrap(); let idempotency_key = guard.runtime.rng(); guard.events.push(IdempotentEvent { @@ -158,6 +158,22 @@ impl Client { self.process_events(guard, true); } + pub fn push_many(&mut self, events: impl Iterator) { + let mut guard = self.inner.try_lock().unwrap(); + for event in events { + let idempotency_key = guard.runtime.rng(); + guard.events.push(IdempotentEvent { + idempotency_key, + name: event.name, + timestamp: event.timestamp, + user: event.user, + source: event.source, + payload: event.payload, + }); + } + self.process_events(guard, true); + } + pub fn flush_batch(&self) { let guard = self.inner.try_lock().unwrap(); self.flush_batch_within_lock(guard); diff --git a/client/src/tests.rs b/client/src/tests.rs index ebcce42..64f31e4 100644 --- a/client/src/tests.rs +++ b/client/src/tests.rs @@ -16,7 +16,7 @@ fn batch_flushed_when_max_batch_size_reached(flush_synchronously: bool) { for i in 0..10 { for _ in 0..5 { - client.push_event(Event { + client.push(Event { name: i.to_string(), timestamp: 0, user: None, @@ -41,7 +41,7 @@ fn batch_flushed_when_flush_delay_reached(flush_synchronously: bool) { for i in 0..10 { for _ in 0..5 { - client.push_event(Event { + client.push(Event { name: i.to_string(), timestamp: 0, user: None,