Should the asynchronicity be taken into account if the parallel process completely downloads the browser movement?
-
The situation is: the initialization of the facility takes considerable time because there is a need for many counts. In order to continue the next phases of the algorithm, the facility should be fully initiated.
If the initialization process is to be considered as an asynchronous one, a bulbeck function should be used (to guarantee that the next steps will not be carried out before full initialization).
In practice, I see that is not necessary. I mean, asynchronism doesn't show. As far as I understand, the fact is, since the browser's movement is already fully loaded (initialization) it doesn't start implementing other lines of the code.
Question: Will this work well and in all browsers?https://jsfiddle.net/mcga5uyz/
Array length: <span id='result'></span><br /> Может ли случится такое, что подсчет числа членов массива произойдет до его полного инициализирования? <script> function fibonacci(n) { if (n < 2){ return 1; }else{ return fibonacci(n-2) + fibonacci(n-1); } }
var array = [];
function init(){
for(var i=0;i<10;i++){
array[i]=fibonacci(37);
}
}init();
$('#result').text(array.length);
</script>
https://jsfiddle.net/mcga5uyz/
-
In practice, I see that is not necessary. I mean, asynchronism is not. It shows. As long as I'm aware, the point is, moves. The browser is already fully loaded. other lines of the code. Question: whether or not to do so Will all the browsers work that way?
It's not that the move is loaded, it's that JS is one-point.
You have no asynchronous surgery,
Web Worker
You don't use it. Makes sense that everything will be carried out consistently. And by the time$('#result').text(array.length);
Everything will be initiated in any browser.P. S. You always have a mass for all the elements.
fibonacci(37)
Same thing.This option is faster:
function init(){ var fiba = fibonacci(37); for(var i=0;i<10;i++){ array[i] = fiba; } }