Permalink
Browse files

Post PR clean-up and prep for release

  • Loading branch information...
1 parent 93792ff commit 02bd30d5cc4f4dbc24214cd002c50b57768a8f5c @thisandagain committed May 25, 2013
Showing with 50 additions and 9 deletions.
  1. +1 −2 EDQueue/EDQueue.h
  2. +1 −1 EDQueue/EDQueue.m
  3. +24 −6 Project/queue/EDAppDelegate.m
  4. +24 −0 README.md
View
@@ -30,9 +30,8 @@ typedef enum {
@class EDQueue;
@protocol EDQueueDelegate <NSObject>
-@required
-- (EDQueueResult)queue:(EDQueue *)queue processJob:(NSDictionary *)job;
@optional
+- (EDQueueResult)queue:(EDQueue *)queue processJob:(NSDictionary *)job;
- (void)queue:(EDQueue *)queue processJob:(NSDictionary *)job completion:(void (^)(EDQueueResult result))block;
@end
View
@@ -107,7 +107,7 @@ - (void)tick
[self.delegate queue:self processJob:job completion:^(EDQueueResult result) {
[self processJob:job withResult:result];
}];
- }else{
+ } else {
EDQueueResult result = [self.delegate queue:self processJob:job];
[self processJob:job withResult:result];
}
@@ -37,24 +37,42 @@ - (void)applicationWillResignActive:(UIApplication *)application
[[EDQueue sharedInstance] stop];
}
-- (EDQueueResult)queue:(EDQueue *)queue processJob:(NSDictionary *)job
+- (void)queue:(EDQueue *)queue processJob:(NSDictionary *)job completion:(void (^)(EDQueueResult))block
{
sleep(1);
@try {
if ([[job objectForKey:@"task"] isEqualToString:@"success"]) {
- return EDQueueResultSuccess;
+ block(EDQueueResultSuccess);
} else if ([[job objectForKey:@"task"] isEqualToString:@"fail"]) {
- return EDQueueResultFail;
+ block(EDQueueResultFail);
+ } else {
+ block(EDQueueResultCritical);
}
}
@catch (NSException *exception) {
- return EDQueueResultCritical;
+ block(EDQueueResultCritical);
}
-
- return EDQueueResultCritical;
}
+//- (EDQueueResult)queue:(EDQueue *)queue processJob:(NSDictionary *)job
+//{
+// sleep(1);
+//
+// @try {
+// if ([[job objectForKey:@"task"] isEqualToString:@"success"]) {
+// return EDQueueResultSuccess;
+// } else if ([[job objectForKey:@"task"] isEqualToString:@"fail"]) {
+// return EDQueueResultFail;
+// }
+// }
+// @catch (NSException *exception) {
+// return EDQueueResultCritical;
+// }
+//
+// return EDQueueResultCritical;
+//}
+
//
- (void)applicationDidEnterBackground:(UIApplication *)application
View
@@ -60,6 +60,29 @@ In order to keep things simple, the delegate method expects a return type of `ED
- `EDQueueResultFail`: Used to indicate that a job has failed and should be retried (up to the specified `retryLimit`)
- `EDQueueResultCritical`: Used to indicate that a job has failed critically and should not be attempted again
+### Handling Async Jobs
+As of v0.6.0 queue includes a delegate method suited for handling asyncronous jobs such as HTTP requests or [Disk I/O](https://github.com/thisandagain/storage):
+
+```objective-c
+- (void)queue:(EDQueue *)queue processJob:(NSDictionary *)job completion:(void (^)(EDQueueResult))block
+{
+ sleep(1);
+
+ @try {
+ if ([[job objectForKey:@"task"] isEqualToString:@"success"]) {
+ block(EDQueueResultSuccess);
+ } else if ([[job objectForKey:@"task"] isEqualToString:@"fail"]) {
+ block(EDQueueResultFail);
+ } else {
+ block(EDQueueResultCritical);
+ }
+ }
+ @catch (NSException *exception) {
+ block(EDQueueResultCritical);
+ }
+}
+```
+
---
### Methods
@@ -72,6 +95,7 @@ In order to keep things simple, the delegate method expects a return type of `ED
### Delegate Methods
```objective-c
- (EDQueueResult)queue:(EDQueue *)queue processJob:(NSDictionary *)job;
+- (void)queue:(EDQueue *)queue processJob:(NSDictionary *)job completion:(void (^)(EDQueueResult result))block;
```
### Result Types

0 comments on commit 02bd30d

Please sign in to comment.