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

call close handler with correct parameters #56

Merged

Conversation

StarpTech
Copy link
Member

No description provided.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add or update the unit tests?

@StarpTech
Copy link
Member Author

I removed the conditions. There is no case to test I think.

@mcollina
Copy link
Member

I would rather not regress this. Can you add a case similae to the example you added in for fastify?

@StarpTech
Copy link
Member Author

This test fails on the previous code.

@StarpTech
Copy link
Member Author

I also fixed the example #55

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is the best thing to do.
Why you should call close more than one time?
IMHO if a user calls close twice there are two options:

  1. E_TOO_MANY_BEERS 🍻
  2. there is some error in its logic.

I think that if a user calls close more than one time we should log a working and ignore the command or throw an exception.

Thoughts?

@mcollina
Copy link
Member

I agree with you that this is not an easy to understand behavior, but changing it would be semver-major and I prefer to have it fixed it right now. It's not a big change.

@delvedor
Copy link
Member

but changing it would be semver-major

Only if we throw an error. Log a warning and ignore the command is not, because the user has already called close and we are closing the application anyhow.

@mcollina
Copy link
Member

Only if we throw an error. Log a warning and ignore the command is not, because the user has already called close and we are closing the application anyhow.

The user expected the callback to be called.

@StarpTech
Copy link
Member Author

@delvedor In my opinion, it's fine since we are working everywhere with queues. If you can explain it well to the user then it's an easy task.

IMHO if a user calls close twice there are two options: ...

or they split its shutdown routines into several pieces?

@delvedor
Copy link
Member

The user expected the callback to be called.

Ok, then we can call it instantly with an error, such as Closing procedure already started.

app.close(err => {
  console.log(err) // null
})

app.close(err => {
  console.log(err) // 'Closing procedure already started'
})

@delvedor
Copy link
Member

or they split its shutdown routines into several pieces?

@StarpTech what does it mean? You want to close only a part of your application and sometimes after another part?
Why not use two instances of avvio then?

@mcollina
Copy link
Member

The approach you describe in #56 (comment) is correct. However it's a semver-major change, and I would prefer to land this first as a minor/patch.

@StarpTech
Copy link
Member Author

StarpTech commented Mar 31, 2018

@delvedor just realized that close won't propagate errors so it's not a great tool for this. I also tend to #56 (comment) but also removing the queue mechanism from close completely.

Let's discuss this behavior after this PR. This PR will fix a bug in the close handler specification.

Copy link
Member

@delvedor delvedor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@delvedor
Copy link
Member

The approach you describe in #56 (comment) is correct. However it's a semver-major change, and I would prefer to land this first as a minor/patch.

I see it more as a bugfix than a major change.

@mcollina mcollina merged commit caa25ce into fastify:master Mar 31, 2018
@StarpTech StarpTech deleted the feature/#54_consistent_close_interface branch April 3, 2018 22:30
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