azjezz / mutex Goto Github PK
View Code? Open in Web Editor NEWMutex Locking for hack projects
License: MIT License
Mutex Locking for hack projects
License: MIT License
add AzJezz\Mutex\lock()
helper functions.
stub :
function lock<T>((function(): T) $call): ?T;
usage example :
use function AzJezz\Mutex\lock;
function foo(): void {
lock('foo-function', () ==> {
// only one thread at a time may execute this statement
});
}
this would require a new final abstract class MutexRepository
to hold the mutex implementation to use with the lock
helper.
stub :
final abstract class MutexRepository {
public static function set(MutexInterface $mutex);
/**
* Implementation should throw an exception if the repository holds
* no mutex implementations OR return a default implementation.
*
* if the implementation returned a default implementations, it should
* call `set($default)` to ensure that the same instance is returned in the
* next call.
*/
public static function get(): MutexInterface;
}
example :
$lock = await $mutex->acquire(
'foo',
300, // Expiring time in seconds
);
do {
// do things
if (bar()) {
$finished = false;
} else {
$finished = true;
}
if (!$finished && $mutex->getRemainingLifetime($lock) <= 5) {
invariant(!$mutex->isExpired($lock), 'Lock lost during the overall process');
await $mutex->refresh($lock);
}
} while(!$finished);
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.