how to wait until Array is filled (asynchronous)

后端 未结 2 815
温柔的废话
温柔的废话 2021-01-05 16:30

I have an array which is filled asynchronous and contains 28 items. I want to wait until the array is filled with all items.

function checkIfFinished(){
             


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-05 16:52

    Try:

    var timeout = setInterval(function() {
        if(checkIfFinished()) {
            clearInterval(timeout); 
            isFinished = true;
        }
    }, 100);
    

    This will call your check-function every 100 ms until checkIfFinished() gives true back to you.

提交回复
热议问题