Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<blockquote> <p>I can do a window.showModalDialog and put a window.close in the modal dialog with setTimeout of very small time</p> </blockquote> <p>That's inventive, but it only allows for user interaction with anything in the modal dialog, for the length of time it's open. The rest of the browser remains hung as surely as if you'd just called a brutal <code>while (new Date().getTime()&lt;t1);</code> loop.</p> <p>The modal dialog is kinder on CPU cycles and will avoid triggering the script-execution-time watchdog in the case of longer waits, but you'd have to balance that against the annoyance of a distracting flashing-open dialog box, and the non-universal browser support, and the issue of everyone hating modal dialogs!</p> <blockquote> <p>This will be like sleep for small time period and I can call this multiple time if needed. Is there some other way?</p> </blockquote> <p>What are you actually trying to achieve by sleeping? Without returning to the event loop or firing a modal dialog, you're not going to get any on-screen update or user interaction, so I don't see what an inline sleep is going to do for you. You certainly can't do animation this way.</p> <p>In Firefox you get Python-style <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Iterators_and_Generators" rel="nofollow noreferrer">generators</a>, which would allow you to write a procedural-style interaction process using <code>yield</code> to return control to the browser as necessary. This can improve the simplicity of code as you don't have to re-write conditional and looping structures as remembered state in variables. However as only Mozilla browsers support it you can't really use it in the wild for the foreseeable future.</p> <p>ETA:</p> <blockquote> <p>I want to write an ORM with sync api so that developers can use it more easily. To bridge this async to sync api, I need something like sleep.</p> </blockquote> <p>Sorry, can't be done in the general case. Basic JavaScript does not have threads, co-routines or other primitives that can bridge sync and async code.</p> <p>The Web SQL Database spec relies on browsers invoking your result-handling function (passed to <code>executeSql()</code>) as a browser callback. Browser callbacks can only fire when control has passed back to the browser, not inside a synchronous thread of execution.</p> <p>In theory, you could open a modalDialog, do the asynchronous Web SQL Database call <em>inside</em> the <code>modalDialog</code>'s window, and have the modalDialog return the result to synchronous code in the caller window's scripts. However, there is currently no browser that supports both <code>openDatabase</code> <em>and</em> <code>openModalDialog</code>!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload