46

Just found this in a legacy Angular1 app. It's in production btw.

Comments
  • 1
    😶
  • 10
    Why a for loop when you can just use while (true)
  • 1
  • 3
    @filthyranter a timeout haha
  • 4
    Crap.
  • 1
    Angry reacts only. 😠
  • 10
    1) how often is i incremented?

    2) why is the limit hard-coded?

    3) why is a new Date being created every iteration (holy performance Batman)

    4) how long will this actually run??

    Did I miss any big problems? I'm new someone help me troubleshoot this monstrosity
  • 0
    It's only used in one file, for 100ms sleeps. Purpose is unknown but as far as I deduce it's used at the end of the iteratee of a very convoluted for loop, possibly to "make sure" the current iteration is finished before moving on.
  • 2
    On current CPUs it actually has a fairly good chance of blocking for approximately 100ms, but cranking the time up will lead to unexpected results 😀
  • 1
    When you want a synchronous setTimeout /facepalm
  • 0
    @Crazed Lol you're worried about performance? It literally stalls the browser until the time is elapsed.
  • 0
    … or it would, if it didn't give up after 10000000 iterations. @mzeffect
  • 0
    @devios1 "im new" so yes
  • 1
    @Crazed Well the apparent point of this monstrosity is to be as intentionally un-performant (is that a word?) as possible, in order to stall all execution for a given time.

    …which is terrible practice because it will very likely also stall the whole browser, or at least slow it down, when a timeout could have been used to do it asynchronously and …performantly.
Add Comment