Skip to content

Commit

Permalink
added timer to empty the request queue every 2:30, just in case
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Patenaude authored and Matt Patenaude committed Nov 10, 2009
1 parent 30568b4 commit 313fa40
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 279 deletions.
2 changes: 2 additions & 0 deletions LFWebService.h
Expand Up @@ -52,6 +52,8 @@

BOOL runningRequest;
BOOL autoScrobble;

NSTimer *queueTimer;
}

// Initializers
Expand Down
32 changes: 32 additions & 0 deletions LFWebService.m
Expand Up @@ -71,6 +71,7 @@ - (void)dealloc
[scrobbleSubmissionURL release];
[currentTrack release];
[requestQueue release];
[queueTimer release];
[super dealloc];
}

Expand Down Expand Up @@ -229,6 +230,13 @@ - (void)dispatchNextRequestIfPossible
{
if (!runningRequest && [requestQueue count] > 0)
{
if (queueTimer)
{
[queueTimer invalidate];
[queueTimer release];
queueTimer = nil;
}

LFRequest *nextRequest = [requestQueue objectAtIndex:0];

if (([nextRequest requestType] != LFRequestGetToken && [nextRequest requestType] != LFRequestGetSession) && sessionKey == nil)
Expand All @@ -239,6 +247,10 @@ - (void)dispatchNextRequestIfPossible
[nextRequest dispatch];
}
}
- (void)dispatchTimerCalled:(NSTimer *)theTimer
{
[self dispatchNextRequestIfPossible];
}

#pragma mark Request callback methods
- (void)requestSucceeded:(LFRequest *)theRequest
Expand Down Expand Up @@ -365,6 +377,16 @@ - (void)requestSucceeded:(LFRequest *)theRequest
[requestQueue removeObject:theRequest];
if (shouldProceed)
[self dispatchNextRequestIfPossible];
else
{
if (queueTimer)
{
[queueTimer invalidate];
[queueTimer release];
queueTimer = nil;
}
queueTimer = [[NSTimer scheduledTimerWithTimeInterval:150.0 target:self selector:@selector(dispatchTimerCalled:) userInfo:nil repeats:NO] retain];
}
}
- (void)request:(LFRequest *)theRequest failedWithError:(NSError *)theError
{
Expand Down Expand Up @@ -566,6 +588,16 @@ - (void)request:(LFRequest *)theRequest failedWithError:(NSError *)theError

if (shouldProceed)
[self dispatchNextRequestIfPossible];
else
{
if (queueTimer)
{
[queueTimer invalidate];
[queueTimer release];
queueTimer = nil;
}
queueTimer = [[NSTimer scheduledTimerWithTimeInterval:150.0 target:self selector:@selector(dispatchTimerCalled:) userInfo:nil repeats:NO] retain];
}
}

@end
1 change: 1 addition & 0 deletions LFWebServicePrivate.h
Expand Up @@ -35,6 +35,7 @@

// Web service methods
- (void)dispatchNextRequestIfPossible;
- (void)dispatchTimerCalled:(NSTimer *)theTimer;

// Request callback methods
- (void)requestSucceeded:(LFRequest *)theRequest;
Expand Down
42 changes: 18 additions & 24 deletions Last.fm.xcodeproj/matt.mode1v3
Expand Up @@ -229,8 +229,6 @@
<key>Layout</key>
<array>
<dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXBottomSmartGroupGIDs</key>
Expand Down Expand Up @@ -278,13 +276,13 @@
<key>PBXSmartGroupTreeModuleOutlineStateSelectionKey</key>
<array>
<array>
<integer>2</integer>
<integer>1</integer>
<integer>11</integer>
<integer>10</integer>
<integer>0</integer>
</array>
</array>
<key>PBXSmartGroupTreeModuleOutlineStateVisibleRectKey</key>
<string>{{0, 0}, {186, 599}}</string>
<string>{{0, 82}, {186, 599}}</string>
</dict>
<key>PBXTopSmartGroupGIDs</key>
<array/>
Expand Down Expand Up @@ -314,24 +312,26 @@
<key>Dock</key>
<array>
<dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>1CE0B20306471E060097A5F4</string>
<key>PBXProjectModuleLabel</key>
<string>Controller.h</string>
<string>LFWebService.h</string>
<key>PBXSplitModuleInNavigatorKey</key>
<dict>
<key>Split0</key>
<dict>
<key>PBXProjectModuleGUID</key>
<string>1CE0B20406471E060097A5F4</string>
<key>PBXProjectModuleLabel</key>
<string>Controller.h</string>
<string>LFWebService.h</string>
<key>_historyCapacity</key>
<integer>0</integer>
<key>bookmark</key>
<string>C9B454EF10A8F24100B12321</string>
<string>C936E15610A9B1AC005953FF</string>
<key>history</key>
<array>
<string>C9CD586410A35D4D00AB1952</string>
Expand All @@ -353,7 +353,6 @@
<string>C968532E10A7704A003816A7</string>
<string>C968536F10A78CA8003816A7</string>
<string>C91EB8F110A8B08800731192</string>
<string>C91EB8F410A8B08800731192</string>
<string>C91EB8F710A8B08800731192</string>
<string>C91EB8F810A8B08800731192</string>
<string>C91EB91410A8B24D00731192</string>
Expand All @@ -379,7 +378,8 @@
<string>C9B454D610A8F1A500B12321</string>
<string>C9B454E610A8F1FD00B12321</string>
<string>C9B454ED10A8F24100B12321</string>
<string>C9B454EE10A8F24100B12321</string>
<string>C936E15410A9B1AC005953FF</string>
<string>C936E15510A9B1AC005953FF</string>
</array>
</dict>
<key>SplitCount</key>
Expand All @@ -391,14 +391,14 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 0}, {842, 301}}</string>
<string>{{0, 0}, {842, 290}}</string>
<key>RubberWindowFrame</key>
<string>200 186 1050 658 0 0 1440 878 </string>
</dict>
<key>Module</key>
<string>PBXNavigatorGroup</string>
<key>Proportion</key>
<string>301pt</string>
<string>290pt</string>
</dict>
<dict>
<key>ContentConfiguration</key>
Expand All @@ -411,14 +411,14 @@
<key>GeometryConfiguration</key>
<dict>
<key>Frame</key>
<string>{{0, 306}, {842, 311}}</string>
<string>{{0, 295}, {842, 322}}</string>
<key>RubberWindowFrame</key>
<string>200 186 1050 658 0 0 1440 878 </string>
</dict>
<key>Module</key>
<string>XCDetailModule</string>
<key>Proportion</key>
<string>311pt</string>
<string>322pt</string>
</dict>
</array>
<key>Proportion</key>
Expand All @@ -437,9 +437,9 @@
</array>
<key>TableOfContents</key>
<array>
<string>C9B454C810A8EFA700B12321</string>
<string>C936E15710A9B1AC005953FF</string>
<string>1CE0B1FE06471DED0097A5F4</string>
<string>C9B454C910A8EFA700B12321</string>
<string>C936E15810A9B1AC005953FF</string>
<string>1CE0B20306471E060097A5F4</string>
<string>1CE0B20506471E060097A5F4</string>
</array>
Expand Down Expand Up @@ -577,10 +577,6 @@
<integer>5</integer>
<key>WindowOrderList</key>
<array>
<string>C9B454DF10A8F1A500B12321</string>
<string>C9B454E010A8F1A500B12321</string>
<string>1C78EAAD065D492600B07095</string>
<string>1CD10A99069EF8BA00B06720</string>
<string>C9D5C79A10A28A6800AFCF8A</string>
<string>/Users/matt/Last.fm/Last.fm.xcodeproj</string>
</array>
Expand All @@ -606,7 +602,7 @@
<key>PBXProjectModuleGUID</key>
<string>1CD0528F0623707200166675</string>
<key>PBXProjectModuleLabel</key>
<string>UIController.m</string>
<string></string>
<key>StatusBarVisibility</key>
<true/>
</dict>
Expand All @@ -623,8 +619,6 @@
<string>218pt</string>
</dict>
<dict>
<key>BecomeActive</key>
<true/>
<key>ContentConfiguration</key>
<dict>
<key>PBXProjectModuleGUID</key>
Expand Down Expand Up @@ -664,7 +658,7 @@
<key>TableOfContents</key>
<array>
<string>C9D5C79A10A28A6800AFCF8A</string>
<string>C9B454BD10A8EF8D00B12321</string>
<string>C936E15910A9B1AC005953FF</string>
<string>1CD0528F0623707200166675</string>
<string>XCMainBuildResultsModuleGUID</string>
</array>
Expand Down

0 comments on commit 313fa40

Please sign in to comment.