Reputation: 95
The Node.js addons can be evoked in two ways: synchronous and asynchronous. The two ways are possible, so I guess that the synchronous way could be more advantageous in some situation. What is that particular situation?
Upvotes: 0
Views: 95
Reputation: 707376
Pretty much the ONLY time I use the synchronous version of an IO function is in the startup phase of the server. It simplifies the startup code, but does not impact the ultimate scalability or performance of the server. For example, the built-in require()
is synchronous for this reason.
During runtime when processing a request, you pretty much never want to use any synchronous function if there is an asynchronous alternative because it significantly reduces the scalability and performance of your server. It can add some coding complexity to always use the async version, but that extra complexity is what gives node.js it's performance and scalability.
Upvotes: 1