-
-
Notifications
You must be signed in to change notification settings - Fork 75
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
Add option to make creating a Window synchronous #137
Conversation
(This PR is currently based on the synchronous branch, but actually i don't think that's necessary.. I think they touch entirely separate stuff. I can rebase it back onto master if you'd prefer!) |
c80875a
to
744e0dd
Compare
Also, this shaved around 20seconds off of test time on my machine, so that's cool! :) |
Same here. This passes all tests, and I think, greatly simplifies using Blink. Would anyone object to me just merging these in? :)))) |
23767d9
to
e28e525
Compare
3b29fa2
to
e87fcf0
Compare
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.
Okay, I've rebased, which should make this PR much easier to Review. :) Thanks again!!
Overall, I'm less sure about this PR than the last one. It's got a couple weird javascripty and Muxy things in here that i'm pretty unfamiliar with.
A thorough review is definitely appreciated if you have time. :)
res/blink.js
Outdated
// Window creation callback | ||
if (typeof callback_id !== 'undefined') { | ||
Blink.sock.onopen = ()=>{ cb(callback_id, true); } | ||
} |
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 weirded me out a tad. Do you think this is the best place to mark the window as having finished loading? I think so, since by this point it has finished loading all of its blink-related JS, which seems to be the last thing Electron does after creating the window.
But are there any async-y sorts of things I might be missing? Is there a better place to put this that you can think of?
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 seems fine for now -- even if anything is running async at this point communication between Julia and Electron is possible so it makes sense to return from the Window()
call.
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.
Okay excellent. Thanks!
src/AtomShell/window.jl
Outdated
callback = !is_async(opts) | ||
if callback | ||
id, cond = Blink.callback!() | ||
url *= "?callback=$id" |
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.
Also, is there a better way to pass the callback ID than through a query param like this? I'm just not very familiar with the framework being used here. I tried to stick it into req[:params]
like how the page id
is passed (here), but i couldn't figure it out...
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 feel like there should be a better way, but I haven't found it. Good enough for now, imho.
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.
👍 Okay cool! I added a TODO comment there in case someone else comes across it and knows a better way! :)
Also, if you think this looks okay, I'll comment it better before merging. |
This should be good to go after a rebase, imo. |
7b4eb62
to
8d0e960
Compare
@@ -2,6 +2,7 @@ | |||
<html> | |||
<head> | |||
<script>var id = {{id}}</script> | |||
<script>{{optional_create_window_callback}}</script> |
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 to put the <script></script>
tags in the mustache template as well so that there isn't an empty script
node sitting around if the callback isn't being used?
I had it this way originally, because i think it makes the .html file more readable: you know that's going to be a script
node, no matter what its contents end up being.
8d0e960
to
17ddf37
Compare
Okay! I've rebased and commented it better! :) PTAL when you get a chance! Thanks! :) |
9a6a884
to
303fb3e
Compare
303fb3e
to
c8abde2
Compare
Hi, I think the async behavior of If someone would be willing to give it a stamp, I'll merge it in! :) |
Also, one more thought: I currently implemented the |
3bbcf19
to
b412b66
Compare
Okay, PTAL if you can! :) |
Setting `:async=>false` causes `Window()` to block until the window is loaded and the socket is open: ```julia julia> @time Window(Blink.@d(:async=>false)); 0.229105 seconds (4.10 k allocations: 365.495 KiB) julia> @time Window(Blink.@d(:async=>true)); 0.018366 seconds (1.14 k allocations: 39.156 KiB) ``` Defaults to true (async), maintaining previous behavior. Also removed all the now-unneccessary `sleep()`s from all tests.
Change `:async => false` opt to `async=false` keyword argument.
b412b66
to
10cc2ba
Compare
Alright, everything passes. I'm going to Merge this now! It adds a flag, Assuming everyone agrees, we can follow this up with a PR to change those defaults to true! :) |
This is the remaining part of #136: making window creation synchronous.
I've added an
:async
param to the dictionary options to create the window, and it will cause the function to block until the window is created, theblink.js
javascript is loaded, and the WebSocket to communicate with julia is open.This PR definitely needs a design review. I haven't actually done much javascript development ever, so a lot of this was murky water for me. I think it works, but i'm not sure I did everything the best way.
Also, I set the default to be synchronous, with the optional
:async
flag. I think that's the right default value, but just like in #136, we should think about whether to flip it right away or roll this out somehow nicer. That said, I think probably it would be fine to Just Do It! :)For #108