Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

Use steed.each instead of plain loop #153

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/trie_ascoltatore.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

var AbstractAscoltatore = require("./abstract_ascoltatore");
var util = require("./util");
var steed = require("steed");
var defer = util.defer;
var debug = require("debug")("ascoltatori:trie");
var Qlobber = require("qlobber").Qlobber;
Expand Down Expand Up @@ -50,11 +51,12 @@ TrieAscoltatore.prototype.publish = function (topic, message, options, done) {

var cbs = this._matcher.match(topic);

for (var i = 0; i < cbs.length; i++) {
cbs[i](topic, message, options);
function clientCallback(cb, next){
cb(topic, message, options);
next();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you using setImmediate there? And why are you calling done() before the actual callback is called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering a huge (multi hundred thousands) list of forwarder callbacks, Does't setImmediate improve the iteration?Or steed does the same job?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can bring next inside setImmediate right after cb returned. I just felt slow client callbacks should be don't care! so that we can report back from .publish ASAP!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

introducing setImmediate there will increase the total latency

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will change this, thank you

}

defer(done);
steed.each(cbs, clientCallback, done);
};

TrieAscoltatore.prototype.unsubscribe = function unsubscribe(topic, callback, done) {
Expand Down