Skip to content

Commit

Permalink
Fix publisher.js race condition; be more idiomatic
Browse files Browse the repository at this point in the history
  • Loading branch information
fictorial committed Apr 5, 2010
1 parent aff0448 commit c7c14da
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 0 additions & 1 deletion TODO.md
Expand Up @@ -2,7 +2,6 @@

- Use Buffer.growBy in ReplyParser instead of maxReplySize
- Use Buffer.copy in Client generated command send methods when arg is a Buffer to avoid slices
- Fix publisher.js race condition; be more idiomatic
- Add support for Kiwi package manager
- Add support for NPM package manager

Expand Down
16 changes: 9 additions & 7 deletions examples/publisher.js
Expand Up @@ -10,10 +10,12 @@ var client = redis.createClient();

// Publish a message once a second to a random channel.

setInterval(function () {
var channelName = "channel-" + Math.random().toString().substr(2);
var payload = "The time is " + (new Date());
client.publish(channelName, payload, function (err, reply) {
sys.puts("Published message to " + (reply === 0 ? "no one" : (reply + " subscriber(s).")));
});
}, 1000);
client.stream.addListener("connect", function () {
setInterval(function () {
var channelName = "channel-" + Math.random().toString().substr(2);
var payload = "The time is " + (new Date());
client.publish(channelName, payload, function (err, reply) {
sys.puts("Published message to " + (reply === 0 ? "no one" : (reply + " subscriber(s).")));
});
}, 1000);
});

0 comments on commit c7c14da

Please sign in to comment.