Compatible with POSIX systems and Microsoft Windows.
Inheritance: implements Icicle\Concurrent\Sync\MutexInterface
Beispiel #1
0
    /**
     * @coroutine
     *
     * Asynchronously invokes a callable while maintaining an exclusive lock on the container.
     *
     * @param callable<mixed> $callback The function to invoke. The value in the container will be passed as the first
     *     argument.
     *
     * @return \Generator
     */
    public function synchronized(callable $callback)
    {
        /** @var \Icicle\Concurrent\Sync\Lock $lock */
        $lock = (yield $this->mutex->acquire());

        try {
            $value = $this->unwrap();
            $result = (yield $callback($value));
            $this->wrap(null === $result ? $value : $result);
        } finally {
            $lock->release();
        }
    }