Skip to content

Commit

Permalink
sdk: update Realy::get_events_of method
Browse files Browse the repository at this point in the history
  • Loading branch information
yukibtc committed Nov 13, 2023
1 parent df062df commit 6fd9549
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions crates/nostr-sdk/src/relay/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1349,7 +1349,7 @@ impl Relay {
}

/// Get events of filters with custom callback
pub async fn get_events_of_with_callback<F>(
async fn get_events_of_with_callback<F>(
&self,
filters: Vec<Filter>,
timeout: Duration,
Expand Down Expand Up @@ -1378,13 +1378,20 @@ impl Relay {
}

/// Get events of filters
///
/// Get events from local database and relay
pub async fn get_events_of(
&self,
filters: Vec<Filter>,
timeout: Duration,
opts: FilterOptions,
) -> Result<Vec<Event>, Error> {
let events: Mutex<Vec<Event>> = Mutex::new(Vec::new());
let stored_events: Vec<Event> = self
.database
.query(filters.clone())
.await
.unwrap_or_default();
let events: Mutex<Vec<Event>> = Mutex::new(stored_events);
self.get_events_of_with_callback(filters, timeout, opts, |event| async {
let mut events = events.lock().await;
events.push(event);
Expand Down

0 comments on commit 6fd9549

Please sign in to comment.