testing同一个函数的并发调用

我有一个function:

var inRendering = false; function render() { if (inRendering) { requestAnimationFrame(render); } else { inRendering = true; requestAnimationFrame(function () { longAction(); inRendering = false; }); } } 

我必须进行unit testing。 testing并发调用render

请帮帮我? 这样的并发呼叫在JavaScript中可能吗? 谢谢。

PS我写了一个testing,显然不工作(见评论): https : //gist.github.com/kuraga/b0aa3d66fc0620f03b11

你可以使用asynchronous模块,特别是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. });