Concurrency in syncLines
The loop in syncLines does three things:
- call ajax
- unmark dirty (and update localStorage)
- clear old cache (and update localStorage)
The problem is that ajax calls are asynchronous and they also update the localStorage via callbacks.
This may create a clash between the updates of the localStorage.
So it is better to have the pattern getItem/setItem inside a single execution thread.