Skip to content

Commit

Permalink
f Store and return Arc<Event>
Browse files Browse the repository at this point in the history
  • Loading branch information
tnull committed Nov 17, 2022
1 parent 1566dcb commit a45eb9e
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,20 +167,20 @@ impl<K: KVStorePersister> LdkLiteEventQueue<K> {
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)?;
}

self.notifier.notify_one();
Ok(())
}

pub(crate) fn next_event(&self) -> LdkLiteEvent {
pub(crate) fn next_event(&self) -> Arc<LdkLiteEvent> {
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> {
Expand All @@ -205,7 +205,7 @@ impl<K: KVStorePersister> ReadableArgs<Arc<K>> for LdkLiteEventQueue<K> {
}
}

struct EventQueueSerWrapper(VecDeque<LdkLiteEvent>);
struct EventQueueSerWrapper(VecDeque<Arc<LdkLiteEvent>>);

impl Readable for EventQueueSerWrapper {
fn read<R: lightning::io::Read>(
Expand All @@ -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))
}
Expand Down

0 comments on commit a45eb9e

Please sign in to comment.