groue / GRDB.swift

A toolkit for SQLite databases, with a focus on application development
MIT License
6.61k stars 677 forks source link

Does cancelling a ValueObservation guarantee that it will never notify any more value? #1550

Closed groue closed 1 month ago

groue commented 1 month ago

When I read the source code of ValueWriteOnlyObserver.cancel() and ValueConcurrentObserver.cancel(), it looks like the observation is only cancelled after the currently pending writes (previously enqueued in the writer dispatch queue). Can those pending writes trigger value notifications after cancel() is called? If so, we have to fix this.

Related: ideally, cancelling an observation should immediately release the connection. This would help closing database in a clean way, before erasing it from disk.

groue commented 1 month ago

False alert. The transaction observer is indeed removed after all enqueued pending writes, but notification closures are destroyed right on cancellation, effectively preventing the app from being notified of anything once the observation was cancelled.