elli icon indicating copy to clipboard operation
elli copied to clipboard

Keeping state in the lifecycle of a request

Open galdor opened this issue 5 years ago • 5 comments

I'm having issues keeping state in the lifecycle of a request. More precisely, I'd like to be able to pass data between handlers, and between init, preprocess, handle and postprocess in each handler.

It seems to be a common pattern in Erlang to explicitely propagate state, for example in gen_server, but it is not the case in elli.

#35 suggests that the only way is the process dictionary, but the Erlang website has good arguments not to overuse it (https://www.erlang.org/course/advanced#dict).

Is there anyone currently working on a patch to add an explicit state ? Would this kind of patch be accepted ?

galdor avatar Jan 12 '19 13:01 galdor

This kind of patch is certainly welcome! And I don't know if anyone is working on anything similar currently. I had started a branch (see #44), but abadoned it. It'd be cool to use @tsloughter's ctx, but I don't think we're necessarily married to it, if you have a better, reasoned idea.

yurrriq avatar Jan 13 '19 02:01 yurrriq

Got it. I'll try to work on a minimal version and submit a pull request for comments.

galdor avatar Jan 13 '19 12:01 galdor

For future reference, this kind of feature would break the API. Is this ok ? It feels like it would be quite convoluted to support both the presence and absence of state everywhere.

galdor avatar Jan 13 '19 13:01 galdor

We'll need a major version bump then.

yurrriq avatar Jan 14 '19 19:01 yurrriq

What kind of state?

Because with https://github.com/open-telemetry/opentelemetry-erlang we are going with only the process dictionary for context I think we'd do well to define standards and best practices for using the pdict this way.

The ctx library may still be of use but I want to switch it to storing stuff in the pdict instead of returning a record.

tsloughter avatar Jan 17 '20 23:01 tsloughter