how to wait with setTimeout until a variable get loaded and, at the same time, receive HTTP requests!

后端 未结 1 417

I\' ve made a in JavaScript function to check every 100 ms if a global variable is loaded. When the variable will be loaded the function will return the value of the variable as

相关标签:
1条回答
  • 2021-02-10 05:37

    I would probably make the remaining arithmetric operations a callback. Something like:

    function checkVariable()
    {
        if ( myvar != null )
        {
                computeVariable(myVar);
        }
        else
        {
                window.setTimeout("checkVariable();",100);
        }
    } 
    

    Then:

    // arithmetis operations... [1]
    
    myVar = checkVariable();
    
    function computeVariable(myVar) {
      // arithmetic operations that use myVar [2]
    }
    
    0 讨论(0)
提交回复
热议问题