Skip to content

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

@ptarjan

Description

@ptarjan
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.

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