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

Fix FastifyInstance::ready type definition #802

Merged
merged 5 commits into from Feb 26, 2018

Conversation

jeromemacias
Copy link
Contributor

Checklist

  • run npm run test and npm run benchmark
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message and code follows Code of conduct

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.

ready could take up to three parameters.
How can we show that in typescript?
https://github.com/mcollina/avvio#ready

@jeromemacias
Copy link
Contributor Author

@delvedor done ;)

if (err) throw err
server.log.debug(context)
done()
})
Copy link
Member

Choose a reason for hiding this comment

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

You should do done(err).

fastify.d.ts Outdated
ready(readyListener?: () => void): void
ready(readyListener?: (err: Error) => void): void
ready(readyListener?: (err: Error, done: Function) => void): void
ready(readyListener?: (err: Error, context: FastifyInstance<HttpServer, HttpRequest, HttpResponse>, done: Function) => void): void
Copy link
Contributor

Choose a reason for hiding this comment

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

If called without the readyListener parameter, a Promise that resolves to the context is returned.

@jeromemacias
Copy link
Contributor Author

@mcollina @nwoltman Fixed and updated for promise case

fastify.d.ts Outdated
ready(): Promise<FastifyInstance<HttpServer, HttpRequest, HttpResponse>>
ready(readyListener?: (err: Error) => void): void
ready(readyListener?: (err: Error, done: Function) => void): void
ready(readyListener?: (err: Error, context: FastifyInstance<HttpServer, HttpRequest, HttpResponse>, done: Function) => void): void
Copy link
Contributor

Choose a reason for hiding this comment

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

readyListener is not optional for the callback cases so the ? shouldn't be needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, good catch!

})

server.ready(function (err, done) {
if (err) throw err
Copy link
Member

Choose a reason for hiding this comment

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

Should this if statement and throw be removed if using the callback?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should call done(err) before throwing error, @mcollina any opinion ?

Copy link
Member

@delvedor delvedor Feb 22, 2018

Choose a reason for hiding this comment

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

There are not suggested paths on how handle this error, it's a decision that belongs to the user.
For the sake of the test, throw error is ok IMHO.

Copy link
Member

Choose a reason for hiding this comment

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

if there is a done callback, the error should be passed there.

Copy link
Member

Choose a reason for hiding this comment

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

and not thrown

})

server.ready(function (err, context, done) {
if (err) throw err
Copy link
Member

Choose a reason for hiding this comment

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

Same here?

Copy link
Member

@evanshortiss evanshortiss left a comment

Choose a reason for hiding this comment

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

LGTM pending two questions

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

@mcollina mcollina merged commit b4db20a into fastify:master Feb 26, 2018
@jeromemacias jeromemacias deleted the ts_def_up branch February 26, 2018 22:16
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 18, 2022
@Eomm Eomm added the semver-minor Issue or PR that should land as semver minor label Apr 1, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
semver-minor Issue or PR that should land as semver minor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants