technoweenie / twitter-node

Discontinued: check out nTwitter
https://github.com/AvianFlu/ntwitter
MIT License
446 stars 547 forks source link

.end() isn't always called on previous stream when .stream() is called #4

Open ptarjan opened 14 years ago

ptarjan commented 14 years ago
var TwitterNode = require('../lib').TwitterNode
  , sys         = require('sys')
  , assert      = require('assert');

var twit = new TwitterNode({
  user: 'username', 
  password: 'password',
  follow: [12345, 67890],                  // follow these random users
});

twit
  .addListener('tweet', function(tweet) {
    sys.puts("@" + tweet.user.screen_name + ": " + tweet.text);
  })  

  .addListener('limit', function(limit) {
    sys.puts("LIMIT: " + sys.inspect(limit));
  })  

  .addListener('delete', function(del) {
    sys.puts("DELETE: " + sys.inspect(del));
  })  

  .addListener('end', function(resp) {
    sys.puts("wave goodbye... " + resp.statusCode);
  })  

  .stream();

setInterval(function() {
  var user = Math.floor(Math.random() * 10000000);
  sys.puts('Following '+user);
  twit.follow(user);
  twit.stream();
}, 1000);

Gives:

Following 9177227 Following 8287550 Following 5989591 wave goodbye... 200 Following 2983167 Following 9713078 wave goodbye... 200 Following 9638683 wave goodbye... 200 Following 7539247 wave goodbye... 200 Following 8320555 wave goodbye... 200 Following 4808738 Following 1493951 wave goodbye... 200 Following 7033565 wave goodbye... 200 Following 8097783 wave goodbye... 200 Following 8631714 wave goodbye... 200

The problem with this, is that now I get duplicate "tweet" events called for each existing connection that wasn't closed.

tim-smart commented 14 years ago

Does using the latest HEAD on master fix this for you?

ptarjan commented 14 years ago

I haven't checked, and your fixes conflicted with my local changes. I'll try a merge tonight