passport.js and process.nextTick in strategy

express, javascript, node.js, passport.js

Solution

It's only there in the example to show that async authentication is possible. In most cases, you'd be querying a database, so it'd be async in nature. However, the example just has a hard-coded set of users, so the `nextTick` call is there for effect, to simulate an async function.

Problem

I'm facing something new in nodeJS: `process.nextTick` In some strategies code examples for passport.js, we can see ``` passport.use(new LocalStrategy( function (username, password, done) { // asynchronous verification, for effect... process.nextTick(function () { findByUsername(username, function (err, user) { // ... bcrypt.compare(password, user.password, function (err, res) { // ... }); }) }); } )); ``` But in the official documentation, it is not used. (http://passportjs.org/guide/username-password/) What I understand is that `process.nextTick` should be used to defer synchronous stack to not block an event. But in this strategy code, there is no event. What the benefit of doing that here ?

Original source