PHP Class malkusch\lock\mutex\Mutex

Author: Markus Malkusch ([email protected])
Datei anzeigen Open project: malkusch/lock

Public Methods

Method Description
check ( callable $check ) : DoubleCheckedLocking Performs a double-checked locking pattern.
synchronized ( callable $code ) : mixed Executes a block of code exclusively.

Method Details

check() public method

Call {@link DoubleCheckedLocking::then()} on the returned object. Example: $mutex->check(function () use ($bankAccount, $amount) { return $bankAccount->getBalance() >= $amount; })->then(function () use ($bankAccount, $amount) { $bankAccount->withdraw($amount); });
public check ( callable $check ) : DoubleCheckedLocking
$check callable
return malkusch\lock\util\DoubleCheckedLocking The double-checked locking pattern.

synchronized() abstract public method

This method implements Java's synchronized semantic. I.e. this method waits until a lock could be acquired, executes the code exclusively and releases the lock. The code block may throw an exception. In this case the lock will be released as well.
abstract public synchronized ( callable $code ) : mixed
$code callable The synchronized execution block.
return mixed The return value of the execution block.