Back-off and re-try for javascript functions