var arr = [];
var fib = 1;
var sum = 0;
function foo(start,finish){
while(sum<=finish){
sum = start + fib;
start = fib;
fib = sum;
if(sum<=finish){
arr.push(fib);
}
}
console.log(arr);
}
foo(0,10000);
var arr = [];
var fib = 1;
var sum = 0;
var timer;
function foo(start,finish){
timer = setInterval(function(){
// вычисления
if(условие) arr.push(....);
else clearInterval(timer); // отключаем таймер.
}, 1000);
}