处理协程任务的超时

@param \Throwable $e 异常实例
@param mixed $value 当前迭代的值
@return \Throwable
962722
public function handleTaskTimeout(\Throwable $e, $value)
    {
        if ($value != '') {
            $logValue = '';
            dumpInternal($logValue, $value, 0, false);
            $message = 'Yield ' . $logValue . ' message: ' . $e->getMessage();
        } else {
            $message = 'message: ' . $e->getMessage();
        }

        $this->getContext()->getLog()->warning($message);

        return $e;
    }
354817
public function toObject($value)
    {
        if (!is_array($value)) {
            throw new TypeCastException('Is not array');
        }

        foreach ($this->rules as $class => $rule) {
            if ($this->isMatch($rule, $value)) {
                return $this->createInstance($class, $value);
            }
        }

        throw new TypeCastException('Rule not found');
    }
390452
public static function async($value, $throw = null)
    {
        if (!self::$self) {
            throw new \BadMethodCallException('Co::async() must be called along with Co::wait(). ');
        }
        if ($throw !== null) {
            $throw = filter_var($throw, FILTER_VALIDATE_BOOLEAN, [
                'flags' => FILTER_NULL_ON_FAILURE,
            ]);
            if ($throw === null) {
                throw new \InvalidArgumentException("\$throw must be null or boolean.");
            }
        }
        self::$self->start($value, false, $throw);
    }
1044161
public function reverseTransform($value)
    {
        if (null === $value) {
            return;
        }

        if (!\is_array($value)) {
            throw new TransformationFailedException('Expected an array.');
        }

        if ('' === implode('', $value)) {
            return;
        }

        $emptyFields = [];

        foreach ($this->fields as $field) {
            if (!isset($value[$field])) {
                $emptyFields[] = $field;
            }
        }

        if (\count($emptyFields) > 0) {
            throw new TransformationFailedException(sprintf('The fields "%s" should not be empty', implode('", "', $emptyFields)));
        }

        if (isset($value['month']) && !ctype_digit((string) $value['month'])) {
            throw new TransformationFailedException('This month is invalid');
        }

        if (isset($value['day']) && !ctype_digit((string) $value['day'])) {
            throw new TransformationFailedException('This day is invalid');
        }

        if (isset($value['year']) && !ctype_digit((string) $value['year'])) {
            throw new TransformationFailedException('This year is invalid');
        }

        if (!empty($value['month']) && !empty($value['day']) && !empty($value['year']) && false === checkdate($value['month'], $value['day'], $value['year'])) {
            throw new TransformationFailedException('This is an invalid date');
        }

        if (isset($value['hour']) && !ctype_digit((string) $value['hour'])) {
            throw new TransformationFailedException('This hour is invalid');
        }

        if (isset($value['minute']) && !ctype_digit((string) $value['minute'])) {
            throw new TransformationFailedException('This minute is invalid');
        }

        if (isset($value['second']) && !ctype_digit((string) $value['second'])) {
            throw new TransformationFailedException('This second is invalid');
        }

        try {
            $dateTime = new \DateTime(sprintf(
                '%s-%s-%s %s:%s:%s',
                empty($value['year']) ? '1970' : $value['year'],
                empty($value['month']) ? '1' : $value['month'],
                empty($value['day']) ? '1' : $value['day'],
                empty($value['hour']) ? '0' : $value['hour'],
                empty($value['minute']) ? '0' : $value['minute'],
                empty($value['second']) ? '0' : $value['second']
                ),
                new \DateTimeZone($this->outputTimezone)
            );

            if ($this->inputTimezone !== $this->outputTimezone) {
                $dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
            }
        } catch (\Exception $e) {
            throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
        }

        return $dateTime;
    }
634859
public function onExceptionHandle(\Throwable $e)
    {
        try {
            if ($e->getPrevious()) {
                $ce = $e->getPrevious();
                $errMsg = dump($ce, false, true);
            } else {
                $errMsg = dump($e, false, true);
                $ce = $e;
            }

            $this->getContext()->getLog()->error($errMsg);
            $this->outputJson(parent::$stdClass, 'Internal Server Error', 500);
        } catch (\Throwable $ne) {
            getInstance()->log->error('previous exception ' . dump($ce, false, true));
            getInstance()->log->error('handle exception ' . dump($ne, false, true));
        }
    }
656390
public function setValue(string $value = null) : Element
    {
        if (!is_null($value)) {
            $tmp = preg_replace('/[^\d]/', '', $value);
            if (strlen($tmp)) {
                $value = $tmp;
                if ($value{0} != '0') {
                    $value = "0$value";
                }
            }
        }
        return parent::setValue($value);
    }
1011230
public function setCodeType($value)
    {
        if (in_array($value, $this->codeTypeList)) {
            $this->codeType = $value;
        } else {
            throw new \Exception('Wrong code type "' . $value . '". Accepted : numeric, alpha or alphanumeric');
        }

        return $this;
    }
629573
public static function valueOf($value): self
    {
        $strVal = null;

        switch (gettype($value)) {
            case 'object':
                if ($value instanceof StdObject || (\is_object($value) && method_exists($value, '__toString'))) {
                    $strVal = (string) $value;
                }
                break;
            case 'boolean':
                $strVal = $value ? 'true' : 'false';
                break;
            case 'double':
            case 'integer':
            case 'string':
                $strVal = (string) $value;
                break;
        }

        if ($strVal === null) {
            throw new InvalidArgumentException('Unsupported value type!');
        }

        return new static($strVal);
    }
506152
final public static function create($value)
    {
        $key = get_called_class() . $value;

        if (isset(self::$instances[$key])) {
            return self::$instances[$key];
        }

        $values = static::values();
        if (!in_array($value, $values)) {
            throw new \UnexpectedValueException("Value '$value' is not part of the enum " . get_called_class());
        }

        self::$instances[$key] = new static($value);
        return self::$instances[$key];
    }
672976
public function serializeThrowable(Throwable $e)
    {
        $this->class = get_class($e);
        $this->message = $e->getMessage();

        $this->properties = [];

        try {
            $reflection = new ReflectionClass($this->class);

            foreach ($reflection->getProperties() as $property) {
                if ($property->isStatic()) {
                    continue;
                }

                $property->setAccessible(true);

                $name = $property->getName();

                if ($name == 'trace') {
                    continue;
                }

                $value = $property->getValue($e);

                $this->properties[$name] = Maker::make($value);
            }
        } catch (Throwable $ex) {
            //
        }
    }
440804
public function onPhpTick(\Throwable $e = null)
    {
        if (!Start::getCoverage()) {
            return;
        }
        if (empty($e)) {
            $dump = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
            $file = $dump[0]['file'];
            $line = $dump[0]['line'];
            $file = explode('app-debug', $file)[1] ?? null;
            if (!empty($file)) {
                $this->getRedis()->zIncrBy(SwooleMarco::CodeCoverage, 1, $file.':'.$line);
            }
        } else {
            $file = explode('app-debug', $e->getFile())[1] ?? null;
            if (!empty($file)) {
                $this->getRedis()->zIncrBy(SwooleMarco::CodeCoverage, 1, $file.':'.$e->getLine());
            }
            $dump = $e->getTrace();
            foreach ($dump as $one) {
                $file = $one['file'];
                $line = $one['line'];
                $files = explode('app-debug', $file);
                if (count($files) > 1) {
                    $file = $files[1];
                    $this->getRedis()->zIncrBy(SwooleMarco::CodeCoverage, 1, $file.':'.$line);
                } else {
                    break;
                }
            }
        }
    }
376528
public static function fromValue($value) {
        if (is_int($value)) {
            return new Type(Type::TYPE_LONG);
        } elseif (is_bool($value)) {
            return new Type(Type::TYPE_BOOLEAN);
        } elseif (is_double($value)) {
            return new Type(Type::TYPE_DOUBLE);
        } elseif (is_string($value)) {
            return new Type(Type::TYPE_STRING);
        }
        throw new \RuntimeException("Unknown value type found: " . gettype($value));
    }
549842
public function setValue(string $value = null) : Element
    {
        if ($value && !preg_match("@^(https?|ftp)://@", $value)) {
            $value = "http://$value";
        }
        return parent::setValue($value);
    }
225760
public static function FromValue( $value )
	{
		if ( is_string( $value ) && ( ! is_numeric( $value ) || ( ! is_int( $value + 0 ) && is_double( $value + 0 ) ) ) )
		{
			throw XPath2Exception::withErrorCodeAndParams( "FORG0001", Resources::FORG0001, array( $value, "integer" ) );
		}

		if ( is_numeric( $value ) )
		{
			if ( is_infinite( $value ) )
				throw XPath2Exception::withErrorCodeAndParams( "FOAR0001", Resources::FOAR0001, array( $value, "integer" ) );

			if ( $value > PHP_INT_MAX || $value < PHP_INT_MIN )
				throw XPath2Exception::withErrorCodeAndParams( "FOAR0002", Resources::FOAR0002, array( $value, "integer" ) );
		}

		return new Integer( $value );
	}
848693
public function execute($value)
    {
        if (!is_array($value) || count($value) != 2) {
            throw new \Exception('Value for date range comparison should have to values');
        }

        $queryBuilder = $this->getQueryBuilder();

        if (!empty($value[0])) {

            $transformer = new FullTransformer(
                $this->container->getParameter('pedro_teixeira_grid.date.date_format'),
                $this->container->getParameter('locale')
            );
            $date = new \DateTime();
            $transformer->parse($date, $value[0]);

            $queryBuilder->andWhere(
                $queryBuilder->expr()->gte(
                    $this->getIndex(),
                    ":{$this->getIndexClean()}_1"
                )
            )
                ->setParameter(
                    ":{$this->getIndexClean()}_1",
                    $date->format('Y-m-d') . ' 00:00:00'
                );
        }

        if (!empty($value[1])) {

            $transformer = new FullTransformer(
                $this->container->getParameter('pedro_teixeira_grid.date.date_format'),
                $this->container->getParameter('locale')
            );
            $date = new \DateTime();
            $transformer->parse($date, $value[1]);

            $queryBuilder->andWhere(
                $queryBuilder->expr()->lte(
                    $this->getIndex(),
                    ":{$this->getIndexClean()}_2"
                )
            )
                ->setParameter(
                    ":{$this->getIndexClean()}_2",
                    $date->format('Y-m-d') . ' 23:59:59'
                );
        }
    }
645256
public static <T, X extends Throwable> T throwThe(X e) throws X {
        if (e == null) {
            throw new ExceptionNotHandled("Cannot throw null exception.");
        }

        throw e;
    }
1059119
public function setValue($value){

        $returnValue = false;

        if(!is_null($value)){
            try{
                $value = new static::$type($value);
                if(!is_null($value)){
                    $this->value = $value;
                    $returnValue = true;
                }
            }catch(DatatypeException $de){
                $type = '('.gettype($value).')';
                if($type == 'object'){
                    $type .= '('.get_class($value).')';
                }
                throw new AttributeException('Cannot assign the value to attribute: '.static::$name.' -> '.$type.' '.$value);
            }
        }

        return $returnValue;
    }