Skip to content

No access to code return value in case of ExecutionOutsideLockException or LockReleaseException #28

@Furgas

Description

@Furgas

When LockReleaseException or ExecutionOutsideLockException is thrown there is no way to access the return value of the code block (it was executed).

Following change to LockMutex::synchronized() comes to mind:

    public function synchronized(callable $code)
    {
        $this->lock();

        $result = null;
        try {
            $result = $code();
        } finally {
	        try {
		        $this->unlock();
	        } catch (ExecutionOutsideLockException|LockReleaseException $e) {
		        $e->setCodeResult($result);
		        throw $e;
	        }
        }

        return $result;
    }

Also setCodeResult and getCodeResult should be added to both exception classes.

Of course a library user can always extend specific LockMutex subclass (ex. PredisMutex) and override the synchronized() method to deal with this problem, but maybe it's worth incorporating directly into the library.

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