From a45eb9ebdd081beddc8f647e562a2a35d08fb7ff Mon Sep 17 00:00:00 2001 From: Elias Rohrer Date: Thu, 17 Nov 2022 14:03:59 +0100 Subject: [PATCH] f Store and return `Arc` --- src/event.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/event.rs b/src/event.rs index 947063c13..ffe6dd14e 100644 --- a/src/event.rs +++ b/src/event.rs @@ -167,7 +167,7 @@ impl LdkLiteEventQueue { pub(crate) fn add_event(&self, event: LdkLiteEvent) -> Result<(), Error> { { let mut locked_queue = self.queue.lock().unwrap(); - locked_queue.0.push_back(event); + locked_queue.0.push_back(Arc::new(event)); self.persister.persist(EVENTS_PERSISTENCE_KEY, &*locked_queue)?; } @@ -175,12 +175,12 @@ impl LdkLiteEventQueue { Ok(()) } - pub(crate) fn next_event(&self) -> LdkLiteEvent { + pub(crate) fn next_event(&self) -> Arc { let locked_queue = self .notifier .wait_while(self.queue.lock().unwrap(), |queue| queue.0.is_empty()) .unwrap(); - locked_queue.0.front().unwrap().clone() + Arc::clone(&locked_queue.0.front().unwrap()) } pub(crate) fn event_handled(&self) -> Result<(), Error> { @@ -205,7 +205,7 @@ impl ReadableArgs> for LdkLiteEventQueue { } } -struct EventQueueSerWrapper(VecDeque); +struct EventQueueSerWrapper(VecDeque>); impl Readable for EventQueueSerWrapper { fn read( @@ -214,7 +214,7 @@ impl Readable for EventQueueSerWrapper { let len: u16 = Readable::read(reader)?; let mut queue = VecDeque::with_capacity(len as usize); for _ in 0..len { - queue.push_back(Readable::read(reader)?); + queue.push_back(Arc::new(Readable::read(reader)?)); } Ok(EventQueueSerWrapper(queue)) }