简体   繁体   中英

synchronization on server side js (node.js)

I am willing to implement some server side code using node.js.

Does node.js (js) have any synchronization inbuilt.Like we have

synchronized key word in java?

Can i make some code block synchornized?so that at one time only on thread can execute it?

In Node, every code block is synchronized. Node uses cooperative multitasking; the only time another piece of code can run is when the first piece of code returns.

That's the driving force behind its event-driven design: you ask for something slow to be done for you (eg reading from a file), and then you specify another function to be run when that slow operation is done. The first function returns, and Node can run other functions while it's waiting for the I/O operation to be done. When the I/O is ready, and all other functions are done running, then your continuation will be called.

Synchronization isn't needed when you're in full control of when your code will yield. In effect, every function is synchronized.

Node does not use threads. It is based on an event machine...

So I think your question is a little off.. Maybe if you give a problem that you are trying to solve people here can guide you.

是的你可以使用光纤,更多细节http://alexeypetrushin.github.com/synchronize

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM