-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Make EventLoopProxy Sync
#2294
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
Make EventLoopProxy Sync
#2294
Conversation
madsmtm
left a comment
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 agree with this in principle (haven't looked into the implementation yet), however I would like our platforms to not diverge further on what marker traits they implement (since that is a quite hard-to-debug thing).
So maybe we could fix the "web's EventLoopProxy isn't Send/Sync" while we're at it? If not, I don't think EventLoopProxy should be those marker traits on any platform!
|
There are two ways I can think of to implement
Which would you prefer? |
EventLoopProxy Sync (except on the web)EventLoopProxy Sync
|
Okay, I've now implemented |
Also formatted a comment from the iOS impl
|
I'd honestly prefer the "manual" approach, but I don't know how much more work that would be. In either case, the web backend is kind of weird to me in many ways, so I think I'll have to read more of it and then probably consult someone before I feel comfortable with either approach. |
|
Using Also, this isn't as vital for async as I thought - wrapping the |
|
I just stumbled on the same issue, but I only need I would be more then happy to contribute, what would be the current blocker? |
The main problem, at least in my opinion, was that using That's not an issue with the implementation on the web though, so I don't think there'd be any major problems if you copy-pasted that bit into a new PR. You might want to manually make it not |
|
I will make a new PR only for |
|
This can be closed in favor of #2834. We had a brief talk about this on Matrix and decided that this can be done by the user by just wrapping it around a This would also be fixed automatically by rust-lang/rust#111087. |
|
Noting that this has now been fully resolved by #3449. |
CHANGELOG.mdif knowledge of this change could be valuable to usersUpdated documentation to reflect any user-facing changes, including notes of platform-specific behaviorCreated or updated an example program if it would help users understand this functionalityUpdated feature matrix, if new features were added or implementedPreviously,
EventLoopProxywasSendbut notSync. The only reason for this that I could see was thatmpsc::Senderwasn'tSync; however, the alternativempsc::SyncSenderis, so I've switched to using that instead.It's not named that because it implements
Sync; the difference is thatSyncSenderhas a fixed-size buffer and will block if its buffer is full, whereasSenderwill never block. For the size of the buffer, I've just arbitrarily picked 10; I've got no idea what would be optimal.The reason I think it needs to implement
Syncis for the sake of #1199. In an executor which polls futures within the event loop, the best way I can think of to implementWakeris by sending an event throughEventLoopProxyto wake up the event loop; however,WakerisSendandSync, soEventLoopProxyalso has to beSendandSyncfor aWakerimplementation to use it.On the web,EventLoopProxyis neitherSendnorSync. This could be fixed, but would be much more complicated and isn't needed for the async use case - on the web,wasm_bindgen_futures::spawn_localcould just be used instead, so a customWakerimplementation isn't needed.