Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想测试 node.js 中的函数是否是异步的?
该模块的作者说它是异步的,但我想确定一下。我希望有某种方法可以确定它是否真正异步。那么如何检查它是否是异步的呢?
这里有一个简单的方法来测试代码是否是异步的:修改回调中的一个变量,并在函数调用后检查它是否发生了变化:
var async_check = 0; maybe_async(function(){ async_check = 1; }); if(async_check){ console.log("maybe_async was synchronous"); } else { console.log("maybe_async was asynchronous"); }