Table of Contents | Previous | Next | Index


Lock

Provides a way to lock a critical section of code.

Server-side object

Implemented in

NES 3.0

Created by

The Lock constructor:

Lock(); 

Parameters

None.

Failure to construct a new Lock object indicates an internal JavaScript error, such as out of memory.

Property Summary

Property Description
constructor

Specifies the function that creates an object's prototype.

prototype

Allows the addition of properties to the object.

Method Summary

Method Description
isValid

Verifies that this Lock object was properly constructed.

lock

Obtains the lock.

unlock

Releases the lock.

In addition, this object inherits the watch and unwatch methods from Object.

See also

project.lock, project.unlock, server.lock, server.unlock

Syntax

lock(timeout)

Parameters

timeout

An integer indicating the number of seconds to wait for the lock. If 0, there is no timeout; that is, the method waits indefinitely to obtain the lock. The default value is 0, so if you do not specify a value, the method waits indefinitely.

Returns

True if it succeeds in obtaining the lock within the specified timeout. False if it did not obtain the lock.

Description

You can obtain a lock for an object to ensure that different clients do not access a critical section of code simultaneously. When an application locks an object, other client requests must wait before they can lock the object.

Note that this mechanism requires voluntary compliance by asking for the lock in the first place.

See also

Lock.unlock, Lock.isValid, project.lock, server.lock


constructor

Specifies the function that creates an object's prototype. Note that the value of this property is a reference to the function itself, not a string containing the function's name.

Property of

Lock

Implemented in

NES 2.0

Description

See Object.constructor.


isValid

Verifies that this Lock object was properly constructed.

Method of

Lock

Implemented in

NES 3.0

Syntax

isValid()

Parameters

None.

Returns

True, if this object was properly constructed; otherwise, false.

Description

It is very rare that your Lock object would not be properly constructed. This happens only if the runtime engine runs out of system resources while creating the object.

Examples

This code creates a Lock object and verifies that nothing went wrong creating it:

// construct a new Lock and save in project 
project.ordersLock = new Lock();
if (! project.ordersLock.isValid()) {
   // Unable to create a Lock. Redirect to error page
   ...
}

See also

Lock.lock, Lock.unlock


lock

Obtains the lock. If someone else has the lock, this method blocks until it can get the lock, the specified timeout period has elapsed, or an error occurs.

Method of

Lock

Implemented in

NES 3.0


prototype

Represents the prototype for this class. You can use the prototype to add properties or methods to all instances of a class. For information on prototypes, see Function.prototype.

Property of

Lock

Implemented in

NES 2.0


unlock

Releases the lock.

Method of

Lock

Implemented in

NES 3.0

Syntax

unlock()

Parameters

None.

Returns

False if it fails; otherwise, true. Failure indicates an internal JavaScript error or that you attempted to unlock a lock that you don't own.

Description

If you unlock a lock that is unlocked, the resulting behavior is undefined.

See also

Lock.lock, Lock.isValid, project.unlock, server.unlock


Table of Contents | Previous | Next | Index

Last Updated: 11/13/98 10:23:22

Copyright 1998 Netscape Communications Corporation