-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
A way to instantiate a resource that must be a singleton inside a dev environment #18264
Comments
From a quick look, class MyEnv extends DevEnvironment {
init({ isRestart }) {
if (isRestart) {
// recreate it here
globalThis.__something.close()
globalThis.__something = new SomeResource(someOptions)
// or maybe resource can restart itself
// globalThis.__something.restart(someOptions)
} else {
globalThis.__something = new SomeResource(someOptions)
}
}
// then what to do here?
// close() {}
} For class MyEnv extends DevEnvironment {
public resource;
listen() {
this.resource = new SomeResource(someOptions)
}
close() {
this.resource.close();
}
} If I have |
Oh, that's right. @patak-dev Did you have something in mind that resolve this problem for the |
I wasn't thinking on a |
I see. Yeah, I think we need a way to take over the previous state (e.g. using the same port and not finding a random port again). |
It isn't easy for me to decide which approach is best. I'm tempted to include both of them as experimental and let the ecosystem play with them. Worse case we deprecate one later on. Do you have a preference here? |
I slightly prefer #18263. It feels easier to understand for me. class MyDevEnvironment {
#server: MyServer
async init({ options, previousInstance }) {
const port = previousInstance?.server.port ?? 5179
this.#server = createServer(port, this.config)
}
async listen() {
await this.#server.listen()
}
async close() {
await this.#server.close()
}
} class MyDevEnvironment {
#server: MyServer
async init({ options }) {
const port = previousInstance?.server.port ?? 5179
this.#server = createServer(port)
await this.#server.listen()
}
async restart(newConfig) {
const port = this.#server.port
await this.#server.close()
this.#server = createServer(port, newConfig)
await this.#server.listen()
}
async close() {
await this.#server.close()
}
} |
Description
configureServer
has the same problem: #17285Suggested solution
Made two PRs with different approach.
feat: add isRestart for environment #18262feat: addenvironment::restart
#18353environment::listen
#18263Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: