Closed xpader closed 1 year ago
You can use FiberLocals for that, see https://github.com/revoltphp/event-loop/blob/main/examples/fiber-local-automatic.php
That's great, I'll try that.
I have create a Context to do that: https://github.com/wind-framework/wind-framework/blob/fafe298933405a511fcc297ef4a1079020b6779d/src/base/Context.php. It works well for request instance in https://github.com/wind-framework/web/blob/24eb5d3a2d7b1299911db3caea8f8c4cd2fac59e/src/Request.php#L314
I have another question, FiberLocal implement base on Fiber::getCurrent(), does Fiber has a parent Fiber or sub Fiber? Is this may broke FiberLocal.
There's no such concept like a parent context currently.
Thanks.
In Swoole extension, the Swoole\Coroutine class has getContext(), getCid(), getPcid(), that can help to create a context for the coroutine. What's that mean? that mean we can use like 'Request::get()' to get input variables like $_GET, or
User::getCurrentUser()
without pass $request object to the method. We can store some values in the context for coroutine and don't need pass the source object in all the call stack.