amphp / amp

A non-blocking concurrency framework for PHP applications. 🐘

Home Page:https://amphp.org/amp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any way to create or get a context for coroutine.

xpader opened this issue · comments

commented

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.

commented

That's great, I'll try that.

commented

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.

commented

Thanks.