Remove typed throws in some Ndb functions
Those are unused and it causes awkward implementations when different error types need to be used. Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
This commit is contained in:
@@ -18,12 +18,12 @@ extension Ndb {
|
|||||||
/// - maxSimultaneousResults: Maximum number of initial results to return
|
/// - maxSimultaneousResults: Maximum number of initial results to return
|
||||||
/// - Returns: AsyncStream of StreamItem events
|
/// - Returns: AsyncStream of StreamItem events
|
||||||
/// - Throws: NdbStreamError if subscription fails
|
/// - Throws: NdbStreamError if subscription fails
|
||||||
func subscribe(filters: [NostrFilter], maxSimultaneousResults: Int = 1000) throws(NdbStreamError) -> AsyncStream<StreamItem> {
|
func subscribe(filters: [NostrFilter], maxSimultaneousResults: Int = 1000) throws -> AsyncStream<StreamItem> {
|
||||||
let ndbFilters: [NdbFilter]
|
let ndbFilters: [NdbFilter]
|
||||||
do {
|
do {
|
||||||
ndbFilters = try filters.toNdbFilters()
|
ndbFilters = try filters.toNdbFilters()
|
||||||
} catch {
|
} catch {
|
||||||
throw .cannotConvertFilter(error)
|
throw NdbStreamError.cannotConvertFilter(error)
|
||||||
}
|
}
|
||||||
return try self.subscribe(filters: ndbFilters, maxSimultaneousResults: maxSimultaneousResults)
|
return try self.subscribe(filters: ndbFilters, maxSimultaneousResults: maxSimultaneousResults)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -710,22 +710,22 @@ class Ndb {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func subscribe(filters: [NdbFilter], maxSimultaneousResults: Int = 1000) throws(NdbStreamError) -> AsyncStream<StreamItem> {
|
func subscribe(filters: [NdbFilter], maxSimultaneousResults: Int = 1000) throws -> AsyncStream<StreamItem> {
|
||||||
guard !self.is_closed else { throw .ndbClosed }
|
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
|
// 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
|
// This ensures that any events indexed after subscription but before query won't be missed
|
||||||
let newEventsStream = ndbSubscribe(filters: filters)
|
let newEventsStream = ndbSubscribe(filters: filters)
|
||||||
|
|
||||||
// Now fetch initial results after subscription is registered
|
// 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
|
// Use our safe wrapper instead of direct C function call
|
||||||
let noteIds = try query(with: txn, filters: filters, maxResults: maxSimultaneousResults)
|
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
|
// Create a cascading stream that combines initial results with new events
|
||||||
return AsyncStream<StreamItem> { continuation in
|
return AsyncStream<StreamItem> { continuation in
|
||||||
|
|||||||
Reference in New Issue
Block a user