You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
conststoreProm=(async()=>{constclient=createClient();awaitclient.connect();returnclient;})();// Can use the client promise
If I want to use Redis as a KV store, it needs to be initialized and awaited:
constclient=createClient();// Need to await, which we might not yet be in the right place to do soawaitclient.connect();constapi=fch.create({cache: {store: client}});
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:
conststore=awaitcreateClient().connect();constapi=fch.create({cache: { store }});
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:
// Currentlyconststore=swear((async()=>{constclient=createClient();awaitclient.connect();returnclient;})());awaitstore.set('a','b');awaitstore.get('a');// If .connect() returned a Promise<client>conststore=swear(createClient().connect());awaitstore.set('a','b');awaitstore.get('a');
Basic Code Example
// Would love to do this:conststore=awaitcreateClient().connect();constapi=fch.create({cache: { store }});// Which would also unlock also this with my library `swear`:conststore=swear(createClient().connect());awaitstore.set('a','b');awaitstore.get('a');
The text was updated successfully, but these errors were encountered:
I'd be happy to try giving it a stab at it, I believe it would be here:
// Beforeconnect(): Promise<void>{// see comment in constructorthis.#isolationPool ??=this.#initiateIsolationPool();returnthis.#socket.connect();}// Afterasyncconnect(): Promise<RedisClientType>{// see comment in constructorthis.#isolationPool ??=this.#initiateIsolationPool();awaitthis.#socket.connect();returnthis;}
@bigDP This is already done in #2602 (and should've been closed when I merged it, which did not happen for some reason). Sorry for the confusion, and thanks for wanting to contribute! :)
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: