message-hub-rest icon indicating copy to clipboard operation
message-hub-rest copied to clipboard

ConsumerInstance.prototype.get: Promise caching error

Open NickCis opened this issue 8 years ago • 0 comments

ConsumerIntances.prototype.get has a caching method when there is a pending promise for a given topic.

When this method is queried several times, only the first promise has the correct output, the following ones have incorrect responses.

Example:

const MessageHub = require('message-hub-rest');
const instance = new MessageHub(config);
instance
  .consume('a-nice-group', 'a-nice-id', {'auto.offset.reset': 'largest'})
  .then(consumers => consumers[0])
  .then(consumer => {
    consumer.get('topic').then(d => console.log(d));
    // Outputs: `[]`
    consumer.get('topic').then(d => console.log(d));
    // Outputs: `{ '0': [] }`
    consumer.get('topic').then(d => console.log(d));
    // Outputs: `{ '0': [] }`
  });

This PR fixes this issue.

NickCis avatar Jun 22 '17 19:06 NickCis