Search code examples
javascriptwindowswinjs

What happens when you use WinJS.Promise.Timeout(undefined)?


I am trying to write a Windows app. I am curious to know what happens when you pass WinJS.Promise.Timeout() undefined value rather than a numerical milliseconds value. Will it be equivalent to passing the function a value of 0, or the behavior is unpredictable?


Solution

  • According to the code the setImmidiate function is called when this value is not specified. This means the promise is fulfilled when the current task is completed.

    When you pass 0 a JavaScript setTimeout function is used internally. This function is limited to 250 calls per second on some systems. When passing 'undefined' to WinJS.Promise.Timeout() it doesn't use a setTimeOut call. So it could be a bit faster in some cases.

    You can find more info on the setImmidate function on MSDN.