-
Notifications
You must be signed in to change notification settings - Fork 910
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
On Web, implement Send
and Sync
for Window
and EventLoopProxy
#2740
Conversation
3eb36d8
to
5b27c40
Compare
Just a side note, Winit window is only tested for |
Lines 5 to 9 in fbea75d
Or do you mean more then just this simple test? |
5b27c40
to
6b3a19f
Compare
Ugh, I guess it's fine then. it's rather strange requirement given that you can't clone it... I know that you must have |
It can be cloned when used in an At least that's my use-case, @Liamolucko described some additional requirements in #2294. |
So I played around with this a bit more, added some comments, prevented leaking unnecessary The only thing left is preventing that one |
(CI fails because of duplicated |
Send
and Sync
for Window
Send
and Sync
for Window
and EventLoopProxy
Closed in favor of #2834. |
This is an experiment to let
Window
implementSend
andSync
on Wasm and reuse the same code to implementSync
forEventLoopProxy
.I took some inspiration from
MainThreadSafe
on macOS.It's implemented in a way that if you call this from the
Window
it will do nothing special and just call the appropriate method on theWindow
, as before. Therefor, except a singleRc<Cell<bool>>
toArc<AtomicBool>
change, there is no overhead if Wasm is only used single-threaded.If used in a multi-threaded environment from a worker, it will use a
mpsc::Sender
to do it's work on the main thread. Currently this is implemented by just sending a boxed function to execute, but it could be rewritten to just send a message and a message handler would then do the right thing.When it's necessary to return a value a
Condvar
and aMutex
is used to await the completion, which would block, but as it's not in the window that should be fine.Most of the small changes here and there are to disallow calls to
web_sys::window()
, as these are the main culprits that will fail if not called from a window. This was necessary because it was quite hard to figure out what needs to be changed, so I added a Clippydisallowed-methods
, which should hopefully make maintenance of this feature easy. Let me know what you think of this.Builds on top of #2732 and #2737.
Fixes #2294.