nickhodge / BoxKite.Twitter

Modern C# Twitter API using .NET Reactive Extensions, async calls
MIT License
41 stars 11 forks source link

Streams only a tweet when another one is recieved #21

Closed danielrozo closed 11 years ago

danielrozo commented 11 years ago

Don't know if this is my implementation or it's a know issue. For example:

userStream.Tweets.Subscribe(t => analyzeTweet(t));
 private async void analyzeTweet(Tweet t)
    {
        if (t.Entities.Mentions.Any(x => x.ScreenName == screenName))
        {
            await dispatcher.RunAsync(CoreDispatcherPriority.High, () => mentions.Add(t));
        }
        await dispatcher.RunAsync(CoreDispatcherPriority.High, () => tweets.Add(t));
    }

Works well, but it'll only add a tweet/mention when another tweet is recieved from the stream, not directly the one just recieved, so it's a 1 tweet delay. I'd bet on my code having some issue, but can't tell which.

nickhodge commented 11 years ago

Hi Daniel

Firstly thanks for giving it a whirl!

Question: have you tried:

userStream.TimeLine.ObserveOn(SynchronizationContext.Current).Subscribe(t => anaylzeTweet(t));

As a mechanism for ensuring the subscriber returns to the correct Thread (assuming it is the UI thread)? This might also save the await dispatcher... in your analyzeTweet method

As another test, can you make the signature of the analyzeTweet to something like

private async Task analyzeTweet(Tweet t)
danielrozo commented 11 years ago

Thans for the quick reply!

Just tried your suggestions, and yes the .ObserveOn saves the dispatcher (currently just testing/exploring the package so it's UI thread). That said, the one tweet delay is still there

nickhodge commented 11 years ago

FIXED in 1.0.5

My error. With the userstreams (and searchstreams) ... if you leave on gzip/deflate the server will hold over data (a packet) before sending. Turn it off, and all is well.

In the midst of all the shenanigans, I also managed to cleanup my code, add more Rx and fix some other bugs. So it was a worthwhile experience.