我有一个功能:
var inRendering = false;
function render() {
if (inRendering) {
requestAnimationFrame(render);
} else {
inRendering = true;
requestAnimationFrame(function () {
longAction();
inRendering = false;
});
}
}
我必须对其进行单元测试。测试并发调用render
的情况。
请帮帮我好吗? JavaScript 中可以实现这种并发调用吗?谢谢。
附注我编写了一个显然不起作用的测试(请参阅评论):https://gist.github.com/kuraga/b0aa3d66fc0620f03b11
最佳答案
您可以使用异步模块,特别是 async.parallel为了并行运行两个函数
例如:
async.parallel([
function(callback){
// run your function once
},
function(callback){
// run your function the second time
}
],
// optional callback
function(err, results){
// the results array will equal ['one','two'] even though
// the second function had a shorter timeout.
});
关于javascript - 测试同一函数的并发调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34862892/