-
Notifications
You must be signed in to change notification settings - Fork 1
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
Initialize state on first request. #31
Conversation
We don't need state to successfully handle some requests, so let's not initialize it until we need it. This wraps the state in a `OnceCell` which is initialized on first use. The `ConnectorSetup` has been split into two to achieve this, because `ParseConfiguration` cannot be made into an object.
configuration_dir: impl AsRef<Path> + Send, | ||
configuration_dir: &Path, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change allows ConnectorSetup
to be "object-safe", which means we can put it in a Box<dyn ConnectorSetup>
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aha! How did you find out? was there a clue in the error message?
I suppose this restriction actually makes sense since f(arg: impl T<X>)
actually becomes f<Y>(arg: Y) where Y impl T<X>
, and if generics are compiled using specialization/erasure rather than passing around a dictionary of trait methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stared it, thought "worth a try", tried it, and it worked! 😛
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Much better shape
We don't need state to successfully handle some requests, so let's not initialize it until we need it.
With these changes, requests to
/capabilities
,/schema
, and/health
will still succeed even if the state cannot be initialized.This wraps the state in a
OnceCell
which is initialized on first use.This changes the
ConnectorSetup
interface, and as such constitutes a breaking change.