stop settimeout in recursive function

后端 未结 7 2129
旧时难觅i
旧时难觅i 2020-12-01 11:24

my problem is that I can not stop a timer.

I had this method to set a timeout from this forum. It supposed to store the identifyer in the global variable. By accid

7条回答
  •  悲哀的现实
    2020-12-01 11:52

    This is a simple pseudocode for controlling and conditioning recursive setTimeout functions.

        const myVar = setTimeout(function myIdentifier() {
    
        // some code
    
        if (condition) {
            clearTimeout(myIdentifier)
        } else {
            setTimeout(myIdentifier, delay); //delay is a value in ms.
        }
    
    }, delay);
    

提交回复
热议问题