Please mind the indentation.

Using a non-zero timeout should be avoided. What are we waiting for exactly? You might want to use a callback or an event listener here.