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

From version 2 - .on(name, handler) returns a promise....?? #74

Open
osher opened this issue Jul 9, 2024 · 3 comments
Open

From version 2 - .on(name, handler) returns a promise....?? #74

osher opened this issue Jul 9, 2024 · 3 comments

Comments

@osher
Copy link

osher commented Jul 9, 2024

From verison 2.0 -
The .on(name:string, handler:function):this API from EventListener now returns a promise.

this breaks the chaining API, because it returns a Promise, which I could not figure what it resolves to - because it does not resolve... 🤔...

I see that .emit(name, payload) also returns a promise...

The code that it breaks for me is in the spirit of:

     new Promise(
          (accept, reject) =>
            mgr.client = c = redis(redisOptions)
            .on('error', reject)
            .on('connect', () => c.removeListener('error', reject) && accept(c)),
        )

I tried to play with it in shell, this is what I managed to isolate:

Welcome to Node.js v20.11.0.
Type ".help" for more information.
> c = require('async-redis').createClient();1
1
> c.on('error', (v, done) => console.log('Err', v) || done()).then(() => console.log('--> on resolved'));
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 96,
  [Symbol(trigger_async_id_symbol)]: 95
}
> c.emit('error', {code:1}).then(() => console.log('--> emit resolved'));
Err { code: 1 }
Promise {
  <pending>,
  [Symbol(async_id_symbol)]: 117,
  [Symbol(trigger_async_id_symbol)]: 115
}
> --> emit resolved

>

I get it with emit although it breaks the EventHandler API...
I would have gone with asyncEmit or something, but that's workable.

But - 🤔 I don't get it, why on should return a promise, and if it does - why won't it resolve?

the current state is not workable...

@osher
Copy link
Author

osher commented Jul 9, 2024

I also see that client.serverInfo.redis_version and such have moved to __redisClient.serverInfo.redis_version

is there a stated accessor to the server info I should use, or is it legit to access __redicClient for that?

@osher
Copy link
Author

osher commented Jul 25, 2024

anybody home?

@osher
Copy link
Author

osher commented Sep 24, 2024

🤔

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

1 participant