envjs / env-js

A pure-JavaScript browser environment.
http://www.envjs.com/
87 stars 19 forks source link

timer event loop exit enhancement #1

Open envjs opened 13 years ago

envjs commented 13 years ago

http://groups.google.com/group/envjs/browse_thread/thread/9a0f4fc1a1cbc501

envjs commented 13 years ago

i think this ticket merits changing the Envjs.exit api call to affect the return value of function so that the return value can be used internally in the Envjs.eventLoop() to condition the loop 'while' to allow the natural event loop to complete before exit.

i also think we should allow an Envjs.exit(force) boolean overload to allow a forceful exit for the event of an end user programmatic loop which never releases control back to the application (similar to unresponsive script warnings).

thatcher

thatcher commented 13 years ago

I have exactly the same problem as Jim in fact, when trying to run EnvJS under Ringo. For the moment, I hacked something like this:

Envjs.exit = function() { throw Envjs.exit } ... { require('envjs/window') } catch(e) { if (e != Envjs.exit) throw e }

But it's really ugly. ;)

Also, more generally, I'm a bit surprised that this event loop is automatically started by window.js . In fact, as a CommonJS module, I would have preferred something allowing me to import window.js without starting any event loop, and returning properly to the code which did the require() at first. Then from this, I can call Envjs.eventLoop() to start the event loop once everything is ok. To make this cleaner, I would suggest creating a tiny module (named for example browser.js) which would do something like this:

Eric

see also http://groups.google.com/group/envjs/browse_thread/thread/9a0f4fc1a1cbc501