I understand that there is some controversy about the name of setImmediate. Does anyone know if this useful functionality will make it into V8/Spider Monkey any time soon, regardless of name?
            Asked
            
        
        
            Active
            
        
            Viewed 903 times
        
    5
            
            
        
        Ben Aston
        
- 53,718
 - 65
 - 205
 - 331
 
- 
                    Isn't it analogous to `setTimeout(funcRef, 0);`? Am I missing something? – crush Aug 17 '15 at 19:32
 - 
                    `setTimeout(funcRef, 0);` [clips to 4ms](https://stackoverflow.com/a/9647221/2039244). Presumably `setImmediate` would not. [Interesting article on this subject](http://www.nczonline.net/blog/2011/09/19/script-yielding-with-setimmediate/). – sdgluck Aug 17 '15 at 19:36
 - 
                    If the task runs immediately, what's the sense in returning an ID that can be cancelled? And is 4ms timer resolution really that big of a deal? – crush Aug 17 '15 at 19:41
 - 
                    A 1GHz CPU can perform 4 million operations in 4ms (at least). Which may or may not be a big deal depending on your use-case. – Ben Aston Aug 17 '15 at 19:46
 - 
                    @BenAston The 15.6ms timer resolution seems like it would be a big deal, but 4ms doesn't seem like it would be enough of a difference to noticeably slow the UI. Assuming that at 0ms setImmediate would pause the thread for nanoseconds each time such a task ran, couldn't you just quadruple these operations up? Would you really notice the impact on the UI thread between 4 and 0 ms? – crush Aug 17 '15 at 20:10
 
1 Answers
1
            https://developer.mozilla.org/en-US/docs/Web/API/Window/setImmediate:
Note: This method is not expected to become standard, and is only implemented by recent builds of Internet Explorer and Node.js 0.10+. It meets resistance both from Gecko (Firefox) and Webkit (Google/Apple).
        CBroe
        
- 91,630
 - 14
 - 92
 - 150
 
- 
                    1So, that's a no, then? It seems that this is a missing feature in those browsers then. setTimeout has a wait time (4ms?) specified in the standard IIUC. Without setImmediate (or at the very least nextTick) there is no clean way to achieve asynchronous behavior without the 4ms noop. – Ben Aston Aug 17 '15 at 19:36
 - 
                    1No clean way; although there are polyfills for it … check the article @sdgluck mentioned already, http://www.nczonline.net/blog/2013/07/09/the-case-for-setimmediate/ for some broader information on the topic. – CBroe Aug 17 '15 at 20:25