Skip to content
Browse files

Added newRequestQueueWithName to the API

  • Loading branch information...
1 parent 84032d9 commit 0640f20bd2cde671168381c7e9e66a3239e15475 @blakewatters blakewatters committed Aug 18, 2011
Showing with 35 additions and 0 deletions.
  1. +6 −0 Code/Network/RKRequestQueue.h
  2. +16 −0 Code/Network/RKRequestQueue.m
  3. +13 −0 Specs/Network/RKRequestQueueSpec.m
View
6 Code/Network/RKRequestQueue.h
@@ -97,6 +97,12 @@
+ (id)requestQueue;
/**
+ Returns a new retained request queue with the given name. If there is already
+ an existing queue with the given name, nil will be returned.
+ */
++ (id)newRequestQueueWithName:(NSString*)name;
+
+/**
Returns queue with the specified name. If no queue is found with
the name provided, a new queue will be initialized and returned.
*/
View
16 Code/Network/RKRequestQueue.m
@@ -65,6 +65,22 @@ + (id)requestQueue {
return [[self new] autorelease];
}
++ (id)newRequestQueueWithName:(NSString*)name {
+ if (RKRequestQueueInstances == nil) {
+ RKRequestQueueInstances = [NSMutableArray new];
+ }
+
+ if ([self requestQueueExistsWithName:name]) {
+ return nil;
+ }
+
+ RKRequestQueue* queue = [self new];
+ queue.name = name;
+ [RKRequestQueueInstances addObject:[NSValue valueWithNonretainedObject:queue]];
+
+ return queue;
+}
+
+ (id)requestQueueWithName:(NSString *)name {
if (RKRequestQueueInstances == nil) {
RKRequestQueueInstances = [NSMutableArray new];
View
13 Specs/Network/RKRequestQueueSpec.m
@@ -188,4 +188,17 @@ - (void)itShouldRemoveTheQueueFromTheNamedInstancesOnDealloc {
assertThatBool([RKRequestQueue requestQueueExistsWithName:@"Images5"], is(equalToBool(NO)));
}
+- (void)itShouldReturnANewOwningReferenceViaNewRequestWithName {
+ RKRequestQueue* requestQueue = [RKRequestQueue newRequestQueueWithName:@"Images6"];
+ assertThat(requestQueue, isNot(nilValue()));
+ assertThatInt([requestQueue retainCount], is(equalToInt(1)));
+}
+
+- (void)itShouldReturnNilIfNewRequestQueueWithNameIsCalledForAnExistingName {
+ RKRequestQueue* queue = [RKRequestQueue newRequestQueueWithName:@"Images7"];
+ assertThat(queue, isNot(nilValue()));
+ RKRequestQueue* queue2 = [RKRequestQueue newRequestQueueWithName:@"Images7"];
+ assertThat(queue2, is(nilValue()));
+}
+
@end

0 comments on commit 0640f20

Please sign in to comment.
Something went wrong with that request. Please try again.