W3C home > Mailing lists > Public > public-web-perf@w3.org > July 2011

Re: Open Source Cross-Browser setImmediate in JavaScript

From: Paul Bakaus <pbakaus@zynga.com>
Date: Thu, 7 Jul 2011 07:11:43 -0700
To: James Robinson <jamesr@google.com>
CC: Donavon West <dwest@book.com>, "public-web-perf@w3.org" <public-web-perf@w3.org>
Message-ID: <CA3B8AB4.AFA9%pbakaus@zynga.com>
That's the thing  I'm wondering out the same thing, so I'd love to know where the difference really is. setTimeout often feels to slow  for instance, to start or restart CSS animations or transitions, you have to wait for a relayout, which is where I'm using setTimeout.

My guess is that setImmediate wouldn't wait for layout batches to be finished, but only JS  so you might call it while code is executing and would know it's executed right after the rest of your current stack has been worked off, but before layout changes.

Von: James Robinson <jamesr@google.com<mailto:jamesr@google.com>>
Datum: Tue, 5 Jul 2011 22:37:22 -0700
An: Paul Bakaus <pbakaus@zynga.com<mailto:pbakaus@zynga.com>>
Cc: Donavon West <dwest@book.com<mailto:dwest@book.com>>, "public-web-perf@w3.org<mailto:public-web-perf@w3.org>" <public-web-perf@w3.org<mailto:public-web-perf@w3.org>>
Betreff: Re: Open Source Cross-Browser setImmediate in JavaScript

Thanks both of you for the feedback.  Could you give some examples (ideally with code) of when you would want to use setImmediate() and why existing mechanisms (like setTimeout()) are not ideal?

- James

On Mon, Jul 4, 2011 at 8:13 AM, Paul Bakaus <pbakaus@zynga.com<mailto:pbakaus@zynga.com>> wrote:
Hi Donavon,

I definitely like this, as process.nextTick seems very efficient. I'm
wondering though if you could give an explanation of the actual difference
between setTimeout and setImmediate. I, for instance, often use it to wait
for reflows and repaints.

Thanks,
Paul

Am 02.07.11 06:43 schrieb "Donavon West" unter <dwest@book.com<mailto:dwest@book.com>>:

>I wrote Jason Weber and he turned me on to this group. Our desktop
>Mac/PC applications use Webkit to create a custom "harness" for our NOOK
>Study higher education ereader (http://nookstudy.com). It looks and
>feels like a native desktop app, but uses web based technologies under
>the hood. As such, we have thousands of lines of rather intense
>JavaScript/HTML5/CSS3 code. As a developer, I really appreciate a faster
>setTimeout(0) alternative and advocate for getting setImmediate into
>future browsers.
>
>I've written a cross-browser JavaScript implementation of setImmediate
>along with a QUnit test suite (which could be used to test browser
>implementations as well). It is open source and you can get it at
>https://github.com/NobleJS/setImmediate (if you build on the tests,
>please update GitHub).
>
>My thoughts on the setImmediate API:
>
>* personally I think that making it semantically identical to the
>setTimeout API was overkill. A simple node.js process.nextTick would
>suffice. I don't think anyone will ever call setImmediate and then clear
>it. However,  for the sake of completeness it doesn't hurt to leave it
>in (you can simply ignore the returned handle).
>* please remove the case for a string eval'ed handler argument. Stop the
>madness! Stop it now!
>
>Donavon West
>Software Development Manager
>Barnes and Noble.com
>
>
>This electronic mail message contains information that (a) is or
>may be CONFIDENTIAL, PROPRIETARY IN NATURE, OR OTHERWISE
>PROTECTED
>BY LAW FROM DISCLOSURE, and (b) is intended only for the use of
>the addressee(s) named herein.  If you are not an intended
>recipient, please contact the sender immediately and take the
>steps necessary to delete the message completely from your
>computer system.
>
>Not Intended as a Substitute for a Writing: Notwithstanding the
>Uniform Electronic Transaction Act or any other law of similar
>effect, absent an express statement to the contrary, this e-mail
>message, its contents, and any attachments hereto are not
>intended
>to represent an offer or acceptance to enter into a contract and
>are not otherwise intended to bind this sender,
>barnesandnoble.com<http://barnesandnoble.com>
>llc, barnesandnoble.com<http://barnesandnoble.com> inc. or any other person or entity.
Received on Thursday, 7 July 2011 14:12:14 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 6 January 2015 21:04:31 UTC