Skip to content

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

@osher

Description

@osher

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...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions