超时退出轮询

Exit polling with timeout

我正在寻找一种优雅的方式来打破这个投票:

private pollLinkResult() {
        (function poll() {
            setTimeout(() => {
                   //call the service layer to do an ajax call
                //depending on the result I would like to exit the infinite poll
            }, 1000);
        })();      
}

有什么想法吗?

private pollLinkResult() {
        (function poll() {
            let myTimeout = setTimeout(() => {
                   //call the service layer to do an ajax call
                //depending on the result I would like to exit the infinite poll
if(yourCondition){
clearTimeout(myTimeout);
}
            }, 1000);
        })();      
}