How do professional Node libraries achieve asynchronous execution?

I spent some time on Node Bcrypt and how they achieved the following asynchronous execution:

bcrypt.hash(myPlaintextPassword, saltRounds, function(err, hash) {
    // Store hash in your password DB.
});

They perform expensive computational tasks (salt generation) using asynchronous callbacks. How do they do this without blocking the main flow of Node IO?

I read about process.nextTick (), but it looks like setTimeout (), in which you distribute the load on the processor over a single thread (delaying payment by piper). Then there is childProcess.fork (), but I don’t think they are using this since I cannot find it anywhere in the GitHub repo .

In addition, you have libraries like Monk that achieve:

users.find({ name: 'Loki' }, '-bigdata').then(function () {
    // exclude bigdata field
})

repo fork(). , , ​​, - .

​​ , , . - , ?

+4
1

node.bcrypt Node-GYP ++ (. /src/directory) Node.

, , .hash , Node , , .

monk, , mongodb (NPM) (GitHub), mongodb-core (NPM) (GitHub), Node net TCP- MongoDB.

+3

Source: https://habr.com/ru/post/1653525/


All Articles