Skip to content

Unsubscribe function unsubscribes all the listeners for the same channel pattern #40

@godness84

Description

@godness84

Just to point out a behavior of this library that is not obvious and that made me wrong.
If you subscribe for the same channel pattern multiple times, and then you call just the first unsubscribe function, then all the other listeners will never receive a message, since the redis client has been unsubscribed from that channel pattern.

In code words:

var unsub1 = nrp.on('say hello', function(data){
  console.log('First Hello ' + data.name);
});

var unsub2 = nrp.on('say hello', function(data){
  console.log('Second Hello ' + data.name);
});

// then at next tick or later
// ...

nrp.emit('say hello', { name: 'Louis' });   // Outputs 'First Hello Louis' and 'Second Hello Louis'

// let's unsubscribe just the first handler.
unsub1();

nrp.emit('say hello', { name: 'Louis' });   // It should output 'Second Hello Louis', but it won't

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