Combine is a set of APIs on how to build recipes for describing asynchronous work, not the values of said work. That means that your publisher is the description of how the work is done, not the results. The sink operation is a way of saying: hey request an unlimited amount of values to kick of the work described and funnel values to this thing until it hits termination or the cancellation token (the AnyCancellable) is either deallocated or explicitly cancelled.
In short; it is better to avoid trying to make such an asynchronous thing synchronous; it will just lead to problems.
The issue that you are likely encountering here is that once that AnyCancellable drops out of scope it cancels the work that would be done - that thing needs to be kept around until you have no more need of values being emitted from it.
Indeed @mazz, if you want players, you can just fetch them right away:
let players = try AppDatabase.shared.databaseReader.read { db in
try Player.fetchAll(db)
}
print(players) // Some actual players (if the db is not empty)
Hi @gwendal.roue so I've been using the synchronous .read up until now and it works great but starting on a new epic in the app's development and I'd like to start fetching things asynchronously as I've noticed when fetching large amounts of data that it is blocking UI presentation.