J
Jorge
With setTimeout you poll the server every 2 seconds + server response
lag (0, 2+[time to response 1], 4+[time to response 2], and so on).
No Diego, not necessarily.
- 1st client request: 0,00 (start point)
- 1st server response: 1,87 seconds (then wait 2,00 seconds)
- 2nd client request 3,87 seconds (result of 1,87 + 2,00 of timeout)
- 2nd server response: 1,99 seconds (then wait 2,00 seconds)
- 3rd client request: 7,86 seconds (result of 3,87 +1,99 +2,00
seconds)
- 3rd server response: 3,00 seconds (then wait 2,00 seconds)
- 4th client request: 12,86 seconds (result of 7,86 +3,00 +2,00
seconds)
... and so on!
Test case with my alghoritm:
- 1st client request: 2,00 (start point)
- 1st server response: 1,87 seconds
- 2nd client request: 4,00
- 2nd server response: 1,99 seconds
- 3rd client request: 6,00
- 3rd server response: 3,00 seconds
- 4th client request: 10,00
... and so on!
You can do that as well with a setTimeout.
In general it's usually better to use a self-re-setting setTimeout
than a setInterval.