Lock.lock()

NES3+Syntax

							lock.lock()

Description

The lock() method of the Lock object locks the code in which you are working until you perform an unlock. If the code is already locked, this method will wait until it can get the lock, a timeout occurs, or an error occurs.

Example

Listing 8.95 assumes there is a project object with a counter property, num. Because you only want to increment the counter with each new user request, it must be locked.

Listing 8.95 Using the lock() Method to Lock Your Code
 <SERVER> // Create a new Lock object under the project object var project.myLock = new Lock(); // Verify the lock if(!project.myLock.isValid()){ write('There has been an error constructing your lock'); }else{ // Lock the code and increment ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.