Intro:The synchronize is nodejs npm module used make the node code synchronized and solve the problem of aysnc programming.it is oposite to the async module of npm and it can good for money relative senstive task.
Problem Facing:I am working on money calculation in MLM(Multi Level Marketing) using neo4j. I have lot of users and i write the code asynchronized for all the user.At same time update hit goes to neo4j and courrept the data and make the calculation wrong.So I search on making the code synchronized in node js.According my reseach two way to make the code synchronized .
- Recursive function
- Synchronized npm module
The recursive function is complex and make lot of effort to make the code synchronized. But synchronize npm is easy and efficent way to make the code synchronized.
Install Procedure:
- npm install synchronize
- var calculateMoney= sync(readFileMethod);//put the reference name of method
Code:
var sync = require('synchronize')
var read = function(a, callback) {
setTimeout(function(){
// remember that callbacks expect (err, result)
callback(null, a)
}, 1000)
}
// We can use the `sync` helper here to avoid using `await()` and `defer()` manually.
read = sync(read);
sync.fiber(function() {
var results = []
results.push(read(1)))
results.push(read(2)))
console.log(results)// results now contains [1,2]
})
Thanks
More From Oodles
Ready to innovate? Let's get in touch
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Himanshu Goyal
Himanshu is a bright Java ,Mean stack developer and have good knowledge of Hibernate, Spring,FFmepg,Neo4j JSON, Jquery, NODE.JS .His hobbies are learning new things, fitness .