Skip to content

DoubleCheckedLocking::then no return value #23

Closed
@TheLevti

Description

@TheLevti

The \malkusch\lock\util\DoubleCheckedLocking::then method does return the return value of the \malkusch\lock\mutex\Mutex::synchronized method.

    /**
     * Executes a code only if a check is true.
     *
     * Both the check and the code execution are locked by a mutex.
     * Only if the check fails the method returns before acquiring a lock.
     *
     * @param callable $code The locked code.
     *
     * @throws \Exception The execution block or the check threw an exception.
     * @throws LockAcquireException The mutex could not be acquired.
     * @throws LockReleaseException The mutex could not be released.
     */
    public function then(callable $code)
    {
        if (!call_user_func($this->check)) {
            return;
        }
        $this->mutex->synchronized(function () use ($code) {
            if (call_user_func($this->check)) {
                call_user_func($code);
            }
        });
    }

I would expect that I can, in addition to pass values by reference in the use part of the callback, return something useful from the synchronized function call so that I can use that result afterwards. For example in a chained method call. Also, when the check fails, it should also return probably false? If the synchronized code will return false to indicate some sort of failure is up to the user. But, when using the ´check(callable)->then(callable)´, I can expect a return value of ´false´ so I know that the check failed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions