Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lock helper. #2

Open
azjezz opened this issue Mar 2, 2019 · 0 comments
Open

lock helper. #2

azjezz opened this issue Mar 2, 2019 · 0 comments
Labels
enhancement New feature or request

Comments

@azjezz
Copy link
Owner

azjezz commented Mar 2, 2019

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;
}
@azjezz azjezz added the enhancement New feature or request label Mar 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant