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

feature: support for display command #13

Open
qiemem opened this issue Oct 3, 2013 · 8 comments
Open

feature: support for display command #13

qiemem opened this issue Oct 3, 2013 · 8 comments

Comments

@qiemem
Copy link
Member

qiemem commented Oct 3, 2013

Jason, Frank, and I have discussed strategies for doing this. The problem is that display must relinquish control of the Javascript thread to give the view a chance to repaint (remember, basic Javascript is single threaded; a website locks while js is running). It must then be able to resume execution as normal. For example:

repeat 50 [ ask turtles [ fd 1 display rt 30 ] ]

Jason suggested having the engine and model code run in a web worker. Then, display just sends out a message to the main thread containing the updates. The downside is that we wouldn't be able to directly call into the engine anymore, which is annoying for debugging and less convenient to embedders. There actually may be a performance hit in that web workers copy messages when sending them. Also, to get the web worker code actually running, we may have to do something weird like concatenating the engine, compat, and the compiled code.

@SethTisue
Copy link
Contributor

another possible solution path is to use ES6's generators, which make JavaScript execution contexts suspendable and resumable. see http://wingolog.org/archives/2013/05/08/generators-in-v8 . they aren't in all browsers yet so I don't think we could use this yet, but maybe in the future.

@qiemem
Copy link
Member Author

qiemem commented Feb 20, 2014

I was also thinking about this. It would definitely be cool.

It's worth noting that Chrome only has them with a special browser flag enabled.

Also, we may want to go the webworker route for performance reasons as well. But the strategies are not mutually exclusive.

@SethTisue
Copy link
Contributor

potentially relevant: “IcedCoffeeScript (ICS) adds two new keywords: await and defer. These additions simply and powerfully streamline asynchronous control flow, both on the server and on the browser. Say goodbye to callback pyramids; say adios to massive code rewrites when synchronization requirements change slightly. Say hello to clean, readable, maintainable control flow for network and asynchronous operations”

@TheBizzle TheBizzle mentioned this issue Jun 10, 2015
@birbilis
Copy link

Btw have you checked if TypeScript supports await keyword and what Javascript it compiles into in that case?

@birbilis
Copy link

...this is related: http://channel9.msdn.com/Events/Build/2015/3-644

@TheBizzle
Copy link
Member

One might be tempted to believe that this problem could be solved by simply passing a callback into the engine that would trigger a view update when called. After all, this is how we do plotting. However, this doesn't work, because the script needs to stop execution entirely for the JavaScript renderer to get its turn in the event queue and render the UI updates. It looks like ES6 generators or webworkers remain the smartest options.

@birbilis
Copy link

BTW, since I had written about TypeScript, now it supports async/await syntax like in C#. It generates JavaScript that is compatible with previous versions. It has good support for several code editors, with the best one being the free Visual Studio Code (for Linux and OS-X too, opensource IDE based on nodejs - https://code.visualstudio.com/), where you can also debug (step into even remote code) etc.

The new version of Angularjs (from Google) is written in TypeScript. Their devs were even present on the stage at Microsoft's latest developer event. See the presentation from 0:33:10 time:
https://channel9.msdn.com/Events/Visual-Studio/Connect-event-2015/010

Father of TypeScript who presents it there is also the father of Turbo Pascal and was chief architect behind Delphi in Borland and lead architect of C# in Microsoft (https://en.wikipedia.org/wiki/Anders_Hejlsberg). So he really knows about programming languages and TypeScript has a bright future for sure

@birbilis
Copy link

btw, a bit unrelated, one could even extend VSCode (https://github.com/microsoft/vscode), since they've now added language plugins etc. to add NetLogo support to it. If I find some time I plan to add some Logo support to it for starters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants