encode / apistar

The Web API toolkit. 🛠
https://docs.apistar.com
BSD 3-Clause "New" or "Revised" License
5.57k stars 411 forks source link

Component initialization and finalization #574

Closed pslacerda closed 6 years ago

pslacerda commented 6 years ago

In 3.x was possible to yield a component with the init function, so initialization and deinitialization was really possible. Currently the only workaround is to use hooks, which a bit confusing because a component code is then scattered in both components and hooks. However even hooks can't work everytime because different component isntances are given to the hook and handler (#490, for exemple on_error hooks).

The impact of this is that is really impossible to finalize components. The only workaround that I can imagine is to use threading.local which is really strange for a single threaded model.

Any thoughts on this?

pslacerda commented 6 years ago

Are pull requests welcome for both this issue and #490?

546 is also related to this issue.

tomchristie commented 6 years ago

I'm not convinced we should support finalization on components.

They should just be a way of providing some argument to a function and not also support a bunch of implicit setup/teardown logic.

tomchristie commented 6 years ago

Similarly #546

pslacerda commented 6 years ago

In fact isn't the same issue as there is more than one way to address that issue (with components or with hooks). I'm saying here to use components.