-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Have client.connect() return a Promise<client> instead of Promise<void> #2601
Labels
Comments
I'd be happy to try giving it a stab at it, I believe it would be here: // Before
connect(): Promise<void> {
// see comment in constructor
this.#isolationPool ??= this.#initiateIsolationPool();
return this.#socket.connect();
}
// After
async connect(): Promise<RedisClientType> {
// see comment in constructor
this.#isolationPool ??= this.#initiateIsolationPool();
await this.#socket.connect();
return this;
} |
I like this idea! :) Wanna open a PR? BTW, don't forget to add a listener to |
3 tasks
Hi, Can i take this task? |
3 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Motivation
It's not possible to create a client in a single step that defers the creation (even if async), so now if we need a promise of the client we need to do this:
If I want to use Redis as a KV store, it needs to be initialized and awaited:
However it'd be nice if we could join both steps into one, so that it could be done in a single step without the extra syntax:
More specifically, I have a library called Swear that is able to very nicely wrap the creation promise and avoid any await at all until the "leaf" function is called and awaited:
Basic Code Example
The text was updated successfully, but these errors were encountered: