Implement Send and Sync for PreparedQuery#445
Conversation
|
Thanks, this is an oversight. In fact, I think these impls should probably be on While fixes to |
59b3d38 to
4f55d2a
Compare
You're right, I'm updating the PR to have the Send + Sync impl's directly on PreparedQuery. Having it on the ChangeTracker was the only thing I was concerned about because as you said PreparedQuery already caches itself. Yes, thanks! I've looked into a event based impl of ChangeTracker. The only issue I've ran into with event-based tracking is live change detection, so I explored using the provided ChangeTracker as a whole before over-optimizing with my own approach. I'm exploring multiple forms of change detection before committing to one specific approach. And that's how I realized the oversight. |
ad9877f to
9007d8f
Compare
| } | ||
|
|
||
| unsafe impl<Q: Query> Send for PreparedQuery<Q> where for<'a> Q::Item<'a>: Send {} | ||
| unsafe impl<Q: Query> Sync for PreparedQuery<Q> where for<'a> Q::Item<'a>: Send {} |
There was a problem hiding this comment.
Are you sure the bound on Sync is correct? Bear in mind that all public methods are &mut. Also please include a safety comment.
To be clear: all queries are automatically cached. |
9007d8f to
e4b8910
Compare
PreparedQuerydoes not automatically implementSendandSyncbecause it retains pointer-capable fetch caches. Its prepared iterators and views already implement both traits when everyQ::Item<'a>isSend; this applies the same bound toPreparedQueryitself.ChangeTrackercontains prepared queries, so it inheritsSend + Synctransitively. This lets multithreaded schedulers store aChangeTrackerwithout introducing a local unsafe newtype.The compile-time test covers prepared shared and mutable queries and confirms that
ChangeTrackerinherits both traits.