Add a Utils.lock as a sync. version of Wrap.localLock.

This commit is contained in:
Edward Lee 2009-06-06 11:52:49 -07:00
parent 042c177ad0
commit 2f189ad5a8
2 changed files with 22 additions and 0 deletions

View File

@ -152,6 +152,7 @@ function WeaveSvc() {
}
WeaveSvc.prototype = {
_lock: Utils.lock,
_localLock: Wrap.localLock,
_catch: Utils.catch,
_catchAll: Wrap.catchAll,

View File

@ -71,6 +71,27 @@ let Utils = {
};
},
/**
* Wrap a function to call lock before calling the function then unlock.
*
* @usage MyObj._lock = Utils.lock;
* MyObj.foo = function() { this._lock(func)(); }
*/
lock: function Utils_lock(func) {
let thisArg = this;
return function WrappedLock() {
if (!thisArg.lock())
throw "Could not acquire lock";
try {
return func.call(thisArg);
}
finally {
thisArg.unlock();
}
};
},
/**
* Wrap functions to notify when it starts and finishes executing or if it got
* an error. The message is a combination of a provided prefix and local name