diff --git a/nostrdb/Ndb+.swift b/nostrdb/Ndb+.swift index 79fc39c1..00b22beb 100644 --- a/nostrdb/Ndb+.swift +++ b/nostrdb/Ndb+.swift @@ -18,12 +18,12 @@ extension Ndb { /// - maxSimultaneousResults: Maximum number of initial results to return /// - Returns: AsyncStream of StreamItem events /// - Throws: NdbStreamError if subscription fails - func subscribe(filters: [NostrFilter], maxSimultaneousResults: Int = 1000) throws(NdbStreamError) -> AsyncStream { + func subscribe(filters: [NostrFilter], maxSimultaneousResults: Int = 1000) throws -> AsyncStream { let ndbFilters: [NdbFilter] do { ndbFilters = try filters.toNdbFilters() } catch { - throw .cannotConvertFilter(error) + throw NdbStreamError.cannotConvertFilter(error) } return try self.subscribe(filters: ndbFilters, maxSimultaneousResults: maxSimultaneousResults) } diff --git a/nostrdb/Ndb.swift b/nostrdb/Ndb.swift index e16daaa3..b171559d 100644 --- a/nostrdb/Ndb.swift +++ b/nostrdb/Ndb.swift @@ -710,22 +710,22 @@ class Ndb { } } - func subscribe(filters: [NdbFilter], maxSimultaneousResults: Int = 1000) throws(NdbStreamError) -> AsyncStream { - guard !self.is_closed else { throw .ndbClosed } + func subscribe(filters: [NdbFilter], maxSimultaneousResults: Int = 1000) throws -> AsyncStream { + guard !self.is_closed else { throw NdbStreamError.ndbClosed } - do { try Task.checkCancellation() } catch { throw .cancelled } + do { try Task.checkCancellation() } catch { throw NdbStreamError.cancelled } // CRITICAL: Create the subscription FIRST before querying to avoid race condition // This ensures that any events indexed after subscription but before query won't be missed let newEventsStream = ndbSubscribe(filters: filters) // Now fetch initial results after subscription is registered - guard let txn = NdbTxn(ndb: self) else { throw .cannotOpenTransaction } + guard let txn = NdbTxn(ndb: self) else { throw NdbStreamError.cannotOpenTransaction } // Use our safe wrapper instead of direct C function call let noteIds = try query(with: txn, filters: filters, maxResults: maxSimultaneousResults) - do { try Task.checkCancellation() } catch { throw .cancelled } + do { try Task.checkCancellation() } catch { throw NdbStreamError.cancelled } // Create a cascading stream that combines initial results with new events return AsyncStream { continuation in