Looking in the NodeJS bcrypt package (https://www.npmjs.com/package/bcrypt), there appears to be pairs of functions for async/sync:
- genSalt/genSaltSync
- hash/hashSync
- compare/compareSync
I understand the purpose of async functions in cases where the function has I/O such as disk or network access, so as not to block the event loop. But what about cases like the above, where there's no I/O, what advantage is there to using the async versions?
What do you lose by choosing the sync versions? I'd like to do so because it makes for simpler code and I can't see any downside to this.
In https://stackoverflow.com/a/11606391/779159 it says "you'd want to use the async version if possible so you're not tying up your node processing during the password hash", but wouldn't your code be tied up anyway since it's CPU that's being used by these functions rather than I/O?