-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pinned Channels #2811
Pinned Channels #2811
Conversation
Visit the preview URL for this PR (updated for commit 1e73fb4): https://yew-rs-api--pr2811-pinned-channels-a6yq3teq.web.app (expires Mon, 22 Aug 2022 18:04:28 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 |
Benchmark - SSRYew Master
Pull Request
|
Size Comparison
✅ None of the examples has changed their size significantly. |
# Conflicts: # packages/yew/src/virtual_dom/vlist.rs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it took me a while to get to this. All the comments are about the same thing: missing safety comment for unsafe
. It's very important to have comments explaining why de-referencing the pointers are important here. Those who aren't familiar with the code can have a hard time understanding what's happening, or worse contribute/merge a change that is unsound. That could be someone new, me or even (future) you.
We should have #[deny(clippy::missing_safety_doc)]
so unsafe functions are checked for this too. It would be great to run miri
in CI. These 2 can be done in separate PRs though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the unsafe blocks are now okay, though a few unsafes can be dropped and the phrasing in the SAFETY comments could be improved to:
SAFETY: the ref is not aliased inside this function and dropped before returning. It will be the only ref to the contents.
Being pedantic, a very odd waker
implementation could trigger re-entrant code and an aliasing mutable borrow, I believe. The borrow is still active after calling out to arbitrary code a8ee1c0#diff-31d23a5f32d50a4ab7bdff4a7fdc162fc1eaf6597c349f407c4076d83b35377cR54 I'm not really concerned about that, though. I believe it's fine to leave as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better off if this were a separate library so non-yew users can also use it?
let inner = unsafe { &mut *self.inner.get() }; | ||
|
||
match (inner.items.pop_front(), inner.closed) { | ||
(Some(m), _) => Poll::Ready(Some(m)), | ||
(None, false) => { | ||
inner.rx_waker = Some(cx.waker().clone()); | ||
Poll::Pending | ||
} | ||
(None, true) => Poll::Ready(None), | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can call try_next
and map the Result<Option<_>, _>
instead duplicating it's implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot avoid acquiring the mutable reference to inner as we have to store the waker.
(it’s an equal number of lines to map Result<Option<_>, _>
to Poll::*
and current implementation.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was hoping to avoid unsafely obtaining the mutable reference. The lines of code doesn't really matter here
let inner = unsafe { &mut *self.inner.get() }; | ||
inner.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about freeing the inner? Does UnsafeCell takes care of it? I couldn't find anything about drop behavior in UnsafeCell documentation, nor does it implement Drop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UnsafeCell is a plain struct with an inner of type T. The drop behaviour is handled normally as any other type.
#[cfg(not(target_arch = "wasm32"))] | ||
#[cfg(feature = "tokio")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we run these tests on both targets?
#[derive(Error, Debug)] | ||
#[error("queue is empty")] | ||
pub struct TryRecvError { | ||
_marker: PhantomData<()>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why have these markers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to mark that there is a hidden information in this struct.
Some other struct have this as we need to expand and add error reason in the future. This is here to keep consistency.
I feel yew::platform should be in its own crate. However, this can be done in a future pull request. |
Co-authored-by: Muhammad Hamza <[email protected]>
1e73fb4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
I agree that yew::platform should be it's own crate. The channels in this PR can be another crate that yew-platform depends upon
Description
This pull request introduces a channel implementation that is
!Send
.Checklist