Attempt to acquire the lock for the given number of seconds.

@param  int  $seconds
@param  callable|null  $callback
@return bool

@throws \Illuminate\Contracts\Cache\LockTimeoutException
434091
public function block($seconds, $callback = null)
    {
        $starting = $this->currentTime();

        while (! $this->acquire()) {
            usleep(250 * 1000);

            if ($this->currentTime() - $seconds >= $starting) {
                throw new LockTimeoutException;
            }
        }

        if (is_callable($callback)) {
            try {
                return $callback();
            } finally {
                $this->release();
            }
        }

        return true;
    }
314082
public function lock(string $name, int $seconds = 0): Lock
    {
        return new CouchbaseLock($this->bucket, $this->prefix.$name, $seconds);
    }
71245
public static function saveCache(string $key, $value, int $seconds = 0): bool
    {
        return self::getInstance()->save($key, $value, $seconds);
    }
93590
def lock(self, seconds=5):
        
        self._current_application().lock(robot.utils.timestr_to_secs(seconds))
219077
public function min(?callable $callback = null)
    {
        return $this->reduce(function ($result, $value, $key) use ($callback) {
            if ($callback !== null) {
                $value = $callback($value, $key);
            }

            return ($result === null) || $value < $result ? $value : $result;
        });
    }
374864
public function acquireLock($entityId, $lockType, $expirationSeconds = null, $retryTimeoutSeconds = null)
        {
            /* Sanitize */
            
            if (is_null($expirationSeconds)) {
                $expirationSeconds = (int)config('locking.expiration_seconds', 30);
            }
            
            if (is_null($retryTimeoutSeconds)) {
                $retryTimeoutSeconds = (int)config('locking.retry_timeout_seconds', 10);
            }
            
            /* Initialize */

            $lock = null;

            if (is_null(Auth::user())) {
                throw new LockTimeoutException();
            }
            $userId = Auth::user()->id;

            /* Attempt to acquire the desired lock */

            $timestampEnd = time() + $retryTimeoutSeconds;
            while (is_null($lock) && time() <= $timestampEnd) {
                /* Determine whether a more important lock is set on the requested entity */

                $needToSleep = false;

                switch ($lockType) {
                    case $this::READ_LOCK:
                        if ($this->isWriteLocked($entityId)) {
                            $needToSleep = true;
                        }

                        break;

                    case $this::WRITE_LOCK:
                        /* We need to check all active locks for this entity */

                        $locks = $this->getLocks($entityId);
                        $activeLockCount = $this->getLocks($entityId)->filter(function ($lock, $key) use ($userId) {
                            // (new Dumper())->dump($lock);
                            return Locking::WRITE_LOCK == $lock->lock_type || $lock->user_id != $userId;
                        })->count();

                        $needToSleep = (0 != $activeLockCount);

                        break;
                }

                if ($needToSleep) {
                    usleep(500000);
                    continue;
                }

                $lock = Lock::create([
                    'user_id'    => Auth::user()->id,
                    'entity_id'  => $entityId,
                    'lock_type'  => $lockType,
                    'expires_at' => Carbon::now()->addSeconds($expirationSeconds),
                ]);
            }

            if (is_null($lock)) {
                throw new LockTimeoutException();
            }

            /* Return lock */

            return $lock->id;
        }
1047391
public function setExpire(int $seconds) : bool
        {
                return $this->_redis->expire($this->_key, $seconds) > 0 ? true : false;
        }
246260
protected function lock(string $key, Closure $callback, int $lockType = LOCK_EX) {
		$filename = $this->generateFilename($key);
		$type     = is_file($filename) ? 'rb+' : 'wb+';
		if ($handle = fopen($filename, $type)) {
			if (flock($handle, $lockType)) {
				$callback($handle);
				flock($handle, LOCK_UN);
				fclose($handle);
				return true;
			}
		}
		return false;
	}
328570
public function set($key, $value, $seconds, $strict = true) {
        $set = $this->memcached->set($key, $value, $seconds);
        if (!$set && $strict) {
            throw new CacheSetException($key);
        }
    }
1183699
public function lock($taskCallable = null, $afterLockCallable = null)
    {
        if($this->isLocked())
        {
            return false;
        }
        if(!$this->__lock())
        {
            return false;
        }
        if(null === $taskCallable)
        {
            return true;
        }
        else
        {
            try {
                if(null !== $afterLockCallable && true === $afterLockCallable())
                {
                    return true;
                }
                $taskCallable();
                return true;
            } catch (\Throwable $th) {
                throw $th;
            } finally {
                $this->unlock();
            }
        }
    }
1329341
public function setReceiveTimeout($seconds = null)
    {
        if (is_integer($seconds)) {
            $this->_rxtimeout = $seconds;
        } else {
            $this->_rxtimeout = self::DEF_TX_RX_TIMEOUT;
        }
        return $this->_rxtimeout;
    }
1127137
@Override
    public boolean setTransactionTimeout(final int _seconds)
    {
        if (JCRStoreResource.LOG.isDebugEnabled()) {
            JCRStoreResource.LOG.debug("setTransactionTimeout (seconds = " + _seconds + ")");
        }
        return true;
    }
1183084
public function remember($key, $minutes, Closure $callback)
    {
        return $this->cache->remember($key, $minutes, $callback);
    }
903688
public function setTimeout($seconds, $microseconds = 0)
    {
        if($resource = $this->getResource()) {
            return stream_set_timeout($resource, $seconds, $microseconds);
        }

        return false;
    }
1235841
public function lock($name, $seconds = 0, $owner = null)
    {
        return new DynamoDbLock($this, $this->prefix.$name, $seconds, $owner);
    }
358119
public function setExpire(int $seconds): bool
    {
        return $this->handle->expire($this->name, $seconds);
    }
1368413
public function timeout(int $seconds): self
    {
        return tap($this, function () use ($seconds) {
            return $this->options = array_merge_recursive($this->options, [
                'timeout' => $seconds,
            ]);
        });
    }