Commit 63750319 authored by Liu lu's avatar Liu lu
Browse files

协程异步兼容hyperf 版本1

parent 959e21a3
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -29,7 +29,7 @@ class AsyncCoroutineAspect extends AbstractAspect
        // 切面切入后,执行对应的方法会由此来负责
        // 切面切入后,执行对应的方法会由此来负责
        // $proceedingJoinPoint 为连接点,通过该类的 process() 方法调用原方法并获得结果
        // $proceedingJoinPoint 为连接点,通过该类的 process() 方法调用原方法并获得结果
        // 在调用前进行某些处理
        // 在调用前进行某些处理
        return Coroutine::create(function ()use($proceedingJoinPoint){
        Coroutine::defer(function ()use($proceedingJoinPoint){
            try {
            try {
                LogTraceHandler::recordProcess(
                LogTraceHandler::recordProcess(
                    '投递到子协程任务,id:'.Coroutine::id()
                    '投递到子协程任务,id:'.Coroutine::id()
@@ -48,6 +48,7 @@ class AsyncCoroutineAspect extends AbstractAspect
                LogTraceHandler::recordProcess($exception,true);
                LogTraceHandler::recordProcess($exception,true);
            }
            }
        });
        });
        return Coroutine::id();




    }
    }
+1 −1
Original line number Original line Diff line number Diff line
@@ -69,7 +69,7 @@ class LogTraceHandler
    private static function getRequestId($isInAsyncCoroutine=false)
    private static function getRequestId($isInAsyncCoroutine=false)
    {
    {
        $workId = posix_getpid();
        $workId = posix_getpid();
        $cid = $isInAsyncCoroutine?Coroutine::parentId(Coroutine::id()):Coroutine::id();
        $cid = Coroutine::id();
        if(!$cid) throw new \Exception('无法使用协程标记录日志');
        if(!$cid) throw new \Exception('无法使用协程标记录日志');
        return container(Server::class)->stats()['start_time'] .$workId. $cid;
        return container(Server::class)->stats()['start_time'] .$workId. $cid;
    }
    }