F
F
fandorin_official2018-02-16 19:18:01
JavaScript
fandorin_official, 2018-02-16 19:18:01

How it is possible to implement that the script "restarted"?

All good. There is a script (see below). Sometimes, it hangs on the checkWrite and readIsOk functions . Please tell me how it can be implemented so that, if i f (index_readIsOk > 200) , the script is restarted, that is, the execution of all functions is interrupted and a new one is started from the start () function.

function start() {
            write = getRead();
            readBtn.onclick(checkWrite(write));
        }
        function checkWrite(last_write){
            result = getRead();
            if (readIsOk(result)) {
                doSomething(result);
            } else {
                setTimeout(checkWrite, 2000);
            }
        }
        function readIsOk(result) {
            index_readIsOk++;
            if (index_readIsOk > 500){
                index_readIsOk = 0;
                return;
                //Вот отсюда, мы должны запустить всё по новой. То-есть function start()
            }
            return result != balance;
        }
        function doSomething(result) {
            index_readIsOk--;
            //что-то делаем тут
        }
        function getRead() {
            //что-то делаем тут
        }
        setInterval(start, 1000);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question