launchdarkly_server_sdk/events/
mod.rs
1use launchdarkly_server_sdk_evaluation::Reference;
2use std::collections::HashSet;
3use std::num::NonZeroUsize;
4use std::sync::Arc;
5use std::time::Duration;
6
7use self::sender::{EventSender, EventSenderResult};
8
9pub mod dispatcher;
10pub mod event;
11pub mod processor;
12pub mod processor_builders;
13pub mod sender;
14
15pub type OnEventSenderResultSuccess = Arc<dyn Fn(&EventSenderResult) + Send + Sync>;
16
17pub struct EventsConfiguration {
18 capacity: usize,
19 event_sender: Arc<dyn EventSender>,
20 flush_interval: Duration,
21 context_keys_capacity: NonZeroUsize,
22 context_keys_flush_interval: Duration,
23 all_attributes_private: bool,
24 private_attributes: HashSet<Reference>,
25 omit_anonymous_contexts: bool,
26 on_success: OnEventSenderResultSuccess,
27}
28
29#[cfg(test)]
30fn create_events_configuration(
31 event_sender: sender::InMemoryEventSender,
32 flush_interval: Duration,
33) -> EventsConfiguration {
34 EventsConfiguration {
35 capacity: 5,
36 event_sender: Arc::new(event_sender),
37 flush_interval,
38 context_keys_capacity: NonZeroUsize::new(5).expect("5 > 0"),
39 context_keys_flush_interval: Duration::from_secs(100),
40 all_attributes_private: false,
41 private_attributes: HashSet::new(),
42 omit_anonymous_contexts: false,
43 on_success: Arc::new(|_| ()),
44 }
45}
46
47#[cfg(test)]
48pub(super) fn create_event_sender() -> (
49 sender::InMemoryEventSender,
50 crossbeam_channel::Receiver<event::OutputEvent>,
51) {
52 let (event_tx, event_rx) = crossbeam_channel::unbounded();
53 (sender::InMemoryEventSender::new(event_tx), event_rx)
54}