Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ensure hook #147

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ayrat555
Copy link

@ayrat555 ayrat555 commented Jul 2, 2017

Sometimes there are situations when an interactor operates with sensible resources, for example, with files. In my opinion, we should have a mechanism to do a final processing on that resources in case an error occurs.

Currently I'm creating a lot of files in my system, location of that files are calculated during execution of interactor and they are available only through interactor's context. So deleting them with ensure_hook solves my problem.

I hope this feature will be useful.

P.S. I will add more tests and docs if everything is ok.

@ayrat555
Copy link
Author

ayrat555 commented Jul 3, 2017

@laserlemon what is your opinion?

@danlo
Copy link

danlo commented Jan 26, 2018

+1

@gaffneyc
Copy link
Member

I'm looking at this and #206 and I don't fully understand the use case or how an Interactor level ensure wouldn't be covered by the ensure mechanism in Ruby itself.

In your example it sounds like you have one Interactor which opens the file and puts it in the Context, several other Interactors that act on the file, then it is closed at some point. The ensure hook would make the pattern more complete by putting the close near the open. Without more context it seems like it could be solved by reorganizing the Interactors such that the processing chain is passed an open file from code that is also responsible for closing the file.

I'm open to a more concrete example for how ensure would help solve a problem. It seems like there is a want for it or a need to better document how to scope Interactors to avoid that need.

@gaffneyc gaffneyc mentioned this pull request Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants