Namespace sync
deal with synchronization between threads in Napa. Lock
is provided for exclusive and shared mutex scenarios.
Exclusive Lock, which is transportable across JavaScript threads.
Use napa.sync.createLock()
to create a lock.
var lock = napa.sync.createLock();
Run input function synchronously and obtain the lock during its execution, returns what the function returns, or throws error if input function throws. Lock will be released once execution finishes.
try {
var value = lock.guardSync(() => {
// DoSomething may throw.
return DoSomething();
});
console.log(value);
}
catch(error) {
console.log(error);
}
An example Synchronized Loading demonstrated how to implement a shared, lazy-loading phone book.