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

Service Singleton? #600

Closed
lukeed opened this issue Dec 15, 2020 · 3 comments
Closed

Service Singleton? #600

lukeed opened this issue Dec 15, 2020 · 3 comments

Comments

@lukeed
Copy link
Contributor

lukeed commented Dec 15, 2020

Is there a reason why startService can't return an existing service channel if one has already been created?

If it's (now) a matter of breaking changes, could we add a reuse?: boolean option?

I have a few integrations in the works, and without something like this, I'm tempted to (A) keep everything under one umbrella so that I can pass around my own singleton value; or (B) create a separate "holding" module that creates/shares a singleton to all callers.

Without this, it's fairly easy to end up with 2-4 esbuild processes running at the same time.

(Can PR)

@evanw
Copy link
Owner

evanw commented Dec 15, 2020

I understand the desire for service consolidation. Each esbuild process will use the same number of threads as cores, so having multiple ones going isn't the best.

It should be possible to do reference-counting with startService() and service.stop() and have a proxy for the same service object be returned as long as the reference count is non-zero. I'd rather not add a new boolean option since doing this is not a breaking change. I'd also rather not literally return the same object as people could be messing with the returned objects and you wouldn't want something messing with the object to accidentally affect something else in strange ways.

I'm happy to do this change myself since it seems like a pretty simple change. But I can take a PR for it if you were looking forward to writing one.

@lukeed
Copy link
Contributor Author

lukeed commented Dec 15, 2020

Cool :) I was offering just so that I wasn't adding to your plate, but I'm headed to bed & don't want you waiting out of sheer politeness lol. Go for it if you have time. I'll open a PR tomorrow if you didn't get to it yet

@evanw evanw closed this as completed in 1f15621 Dec 15, 2020
@lukeed
Copy link
Contributor Author

lukeed commented Dec 15, 2020

Looks good, thanks!

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

No branches or pull requests

2 participants