Skip to content
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

Merged
merged 3 commits into from
Sep 24, 2018

Conversation

NHDaly
Copy link
Collaborator

@NHDaly NHDaly commented Jul 27, 2018

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, the blink.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

@NHDaly
Copy link
Collaborator Author

NHDaly commented Jul 27, 2018

(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!)

@NHDaly NHDaly force-pushed the synchronous_Window branch 3 times, most recently from c80875a to 744e0dd Compare July 27, 2018 20:40
@NHDaly
Copy link
Collaborator Author

NHDaly commented Jul 27, 2018

Also, this shaved around 20seconds off of test time on my machine, so that's cool! :)

@NHDaly
Copy link
Collaborator Author

NHDaly commented Aug 14, 2018

Same here. This passes all tests, and I think, greatly simplifies using Blink.

Would anyone object to me just merging these in? :))))

src/AtomShell/window.jl Outdated Show resolved Hide resolved
@NHDaly NHDaly force-pushed the synchronous_Window branch from 23767d9 to e28e525 Compare August 15, 2018 12:56
@NHDaly NHDaly changed the title Make creating a Window synchronous Add option to make creating a Window synchronous Aug 15, 2018
@NHDaly NHDaly force-pushed the synchronous_Window branch 3 times, most recently from 3b29fa2 to e87fcf0 Compare August 15, 2018 13:05
Copy link
Collaborator Author

@NHDaly NHDaly left a 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); }
}
Copy link
Collaborator Author

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?

Copy link
Member

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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay excellent. Thanks!

callback = !is_async(opts)
if callback
id, cond = Blink.callback!()
url *= "?callback=$id"
Copy link
Collaborator Author

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...

Copy link
Member

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.

Copy link
Collaborator Author

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! :)

@NHDaly
Copy link
Collaborator Author

NHDaly commented Aug 15, 2018

Also, if you think this looks okay, I'll comment it better before merging.

@pfitzseb
Copy link
Member

This should be good to go after a rebase, imo.

@NHDaly NHDaly force-pushed the synchronous_Window branch 2 times, most recently from 7b4eb62 to 8d0e960 Compare September 7, 2018 12:57
@@ -2,6 +2,7 @@
<html>
<head>
<script>var id = {{id}}</script>
<script>{{optional_create_window_callback}}</script>
Copy link
Collaborator Author

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.

@NHDaly NHDaly force-pushed the synchronous_Window branch from 8d0e960 to 17ddf37 Compare September 7, 2018 13:07
@NHDaly
Copy link
Collaborator Author

NHDaly commented Sep 7, 2018

Okay! I've rebased and commented it better! :) PTAL when you get a chance!

Thanks! :)

@NHDaly NHDaly force-pushed the synchronous_Window branch 2 times, most recently from 9a6a884 to 303fb3e Compare September 10, 2018 20:52
@NHDaly
Copy link
Collaborator Author

NHDaly commented Sep 22, 2018

Hi, I think the async behavior of Window() just bit someone, so it would be nice to move forward on this. :)

If someone would be willing to give it a stamp, I'll merge it in! :)

@NHDaly
Copy link
Collaborator Author

NHDaly commented Sep 22, 2018

Also, one more thought: I currently implemented the async option for Window by parsing it out of the opts passed to Window(), but in retrospect I actually don't think that makes any sense. Rereading the code, I've just realized that the opts dict only exists to pass arbitrary options through to Electron. So I'm going to change it now to be a regular, julia keyword parameter. If you have any objections, let me know and I can either stop working on that, or revert the commit if I've already committed it! :)

@NHDaly
Copy link
Collaborator Author

NHDaly commented Sep 22, 2018

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.
@NHDaly
Copy link
Collaborator Author

NHDaly commented Sep 24, 2018

Alright, everything passes. I'm going to Merge this now!

It adds a flag, async, which defaults to true, but with async=false will make Window creation synchronous. This matches the default async=true for body!, etc.

Assuming everyone agrees, we can follow this up with a PR to change those defaults to true! :)

@NHDaly NHDaly merged commit 93aeb16 into JuliaGizmos:master Sep 24, 2018
@NHDaly NHDaly deleted the synchronous_Window branch September 24, 2018 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants