我有这段代码需要转换为异步循环,因为显然这段代码 for-loop 会阻塞 UI/浏览器:
$wnd.mainbuff = [];
$wnd.update = setInterval(function(){
// fetches everything in the buffer (csv), including old data
var temp = $wnd.Recorder.audioData().toString();
var arr = temp.split(',');
// so, copy new elements only (must be async)
for (var i=$wnd.mainbuff.length; i < arr.length; i++) {
console.log(arr[i]);
$wnd.mainbuff[i] = arr[i];
}
}
,25)