How to implement a “function timeout” in Javascript - not just the 'setTimeout'

后端 未结 5 1368
情歌与酒
情歌与酒 2020-12-16 00:33

How to implement a timeout in Javascript, not the window.timeout but something like session timeout or socket timeout - basically - a

5条回答
  •  [愿得一人]
    2020-12-16 00:39

    Share a variable between the observing timer and the executing function.

    Implement the observing timer with window.setTimeout or window.setInterval. When the observing timer executes, it sets an exit value to the shared variable.

    The executing function constantly checks for the variable value.. and returns if the exit value is specified.

提交回复
热议问题