Skip to content

Commit fcafe2c

Browse files
committed
maybe
1 parent a569764 commit fcafe2c

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

Sources/Otter/QueryObservation.swift

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public final class DatabaseQueryObservation<Query>: DatabaseSubscriber, QueryObs
3636
}
3737

3838
public func cancel() {
39+
query.connection.cancel(subscriber: self)
40+
queue.cancel()
41+
3942
lock.withLock {
4043
onChange = nil
4144
onComplete = nil
4245
}
43-
44-
query.connection.cancel(subscriber: self)
45-
queue.cancel()
4646
}
4747

4848
public func start(
@@ -59,9 +59,10 @@ public final class DatabaseQueryObservation<Query>: DatabaseSubscriber, QueryObs
5959
}
6060

6161
private func emitNext() async {
62-
guard let onChange else {
63-
return assertionFailure("Started without handle set")
64-
}
62+
// These are scheduled asynchronously. So there is a timing
63+
// issue where we could `enqueueNext` then get cancelled
64+
// which would bring us to here with no `onChange` set.
65+
guard let onChange else { return }
6566

6667
do {
6768
guard query.transactionKind != .write else {

0 commit comments

Comments
 (0)