Missing wait() function in JavaScript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Streater

    Missing wait() function in JavaScript

    Anyone know whey a wait() function is not provided in JS? Or why the
    function name passed to setTimeout() is a string? That's a real pain in
    the neck for me in my application.

    What would be really nice would be wait(semaphore) matched by
    event(semaphore ), such that setting the event cancelled the wait.

    -- tim
  • Michael Winter

    #2
    Re: Missing wait() function in JavaScript

    On 22/06/2005 11:43, Tim Streater wrote:
    [color=blue]
    > Anyone know whey a wait() function is not provided in JS?[/color]

    In a browser environment, it would be a bad thing: scripts usually run
    in the GUI thread, so waiting would freeze the application.
    [color=blue]
    > Or why the function name passed to setTimeout() is a string?[/color]

    It's not. In many cases, it can also be a function reference. However,
    older implementations will only support string arguments. See
    <URL:http://www.jibbering.c om/faq/faq_notes/misc.html#mtSet TI>.

    [snip]

    Mike

    --
    Michael Winter
    Replace ".invalid" with ".uk" to reply by e-mail.

    Comment

    • Tim Streater

      #3
      Re: Missing wait() function in JavaScript

      In article <Dsbue.54481$G8 .18035@text.new s.blueyonder.co .uk>,
      Michael Winter <m.winter@bluey onder.co.invali d> wrote:
      [color=blue]
      > On 22/06/2005 11:43, Tim Streater wrote:
      >[color=green]
      > > Anyone know whey a wait() function is not provided in JS?[/color]
      >
      > In a browser environment, it would be a bad thing: scripts usually run
      > in the GUI thread, so waiting would freeze the application.[/color]

      Except that, the browser itself is threaded, surely? E.g. in Safari when
      I start it I load 6 or 7 tabs which appear to load asynchronously. If so
      then I would have thought it relatively easy to give access to the
      threads and the wait/event mechanism. This is going to be more efficient
      since it would mean that my waiting function can resume immediately
      instead of waiting for the next timeout (although evidently 50ms is not
      much :-)
      [color=blue][color=green]
      > > Or why the function name passed to setTimeout() is a string?[/color]
      >
      > It's not. In many cases, it can also be a function reference. However,
      > older implementations will only support string arguments. See
      > <URL:http://www.jibbering.c om/faq/faq_notes/misc.html#mtSet TI>.[/color]

      Thanks for this pointer.

      Cheers,

      -- tim

      Comment

      • Michael Winter

        #4
        Re: Missing wait() function in JavaScript

        On 22/06/2005 12:33, Tim Streater wrote:
        [color=blue]
        > In article <Dsbue.54481$G8 .18035@text.new s.blueyonder.co .uk>,
        > Michael Winter <m.winter@bluey onder.co.invali d> wrote:[/color]

        [snip]
        [color=blue][color=green]
        >> In a browser environment, [wait()] would be a bad thing: scripts
        >> usually run in the GUI thread [...][/color]
        >
        > Except that, the browser itself is threaded, surely?[/color]

        Of course, but it is usually just server requests and other I/O
        operations that are threaded. UI updates will be performed by a central
        thread and, as scripts often have a direct affect on presentation and
        content, they will be executed in that same thread.

        A very simple demonstration is to include an alert function call in a
        script in the HEAD element of the document, or part the way through the
        BODY element. You should immediately notice that rendering stops until
        that dialog box is dismissed.

        [snip]

        Mike

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail.

        Comment

        Working...