GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update didResponseJSON to didResponseDictionary. · kevin-lyn/STNetTaskQueue@be1fcdb

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • README.md
  • STNetTaskQueueExample/STNetTaskQueueExample
    • STOpenWeatherNetTask.m
  • STNetTaskQueueTest/STNetTaskQueueTest
    • STTestGetNetTask.m
    • STTestPatchNetTask.m
    • STTestPostNetTask.m
    • STTestPutNetTask.m
  • STNetTaskQueue
    • STHTTPNetTask.h
    • STHTTPNetTask.m
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎README.md‎

Copy file name to clipboardExpand all lines: README.md
+23-5Lines changed: 23 additions & 5 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,20 @@ STHTTPNetTaskQueueHandler *httpHandler = [[STHTTPNetTaskQueueHandler alloc] init
7373
return 3; // Retry after error occurs
7474
}
7575

76+
- (BOOL)shouldRetryForError:(NSError *)error
77+
{
78+
return YES; // Retry for all kinds of errors
79+
}
80+
7681
- (NSDictionary *)parameters
7782
{
7883
return @{ @"lat": self.latitude, @"lon": self.longitude };
7984
}
8085

81-
- (void)didResponseJSON:(NSDictionary *)response
86+
- (void)didResponseDictionary:(NSDictionary *)dictionary
8287
{
83-
_place = response[@"name"];
84-
_temperature = [response[@"main"][@"temp"] floatValue] / 10;
88+
_place = dictionary[@"name"];
89+
_temperature = [dictionary[@"main"][@"temp"] floatValue] / 10;
8590
}
8691

8792
@end
@@ -141,8 +146,21 @@ STHTTPNetTaskQueueHandler *httpHandler = [[STHTTPNetTaskQueueHandler alloc] init
141146
```
142147
For more details, download the example project or check out unit tests for usage references.
143148

149+
### Set max concurrent tasks count of STNetTaskQueue
150+
Sometimes we need to set the concurrent image download tasks to avoid too much data coming at the same time.
151+
152+
```objc
153+
STNetTaskQueue *downloadQueue = [STNetTaskQueue new];
154+
downloadQueue.handler = [[STHTTPNetTaskQueueHandler alloc] initWithBaseURL:[NSURL URLWithString:@"http://example.com"]];
155+
downloadQueue.maxConcurrentTasksCount = 2;
156+
/*
157+
[downloadQueue addTask:task1];
158+
[downloadQueue addTask:task2];
159+
[downloadQueue addTask:task3]; // task3 will be sent after task1 or task2 is finished.
160+
*/
161+
```
162+
144163
## What's Next
145164
146165
- More unit tests for STHTTPNetTaskQueueHandler.
147-
- Detailed documentation for STNetTaskQueue, STNetTask, STNetTaskChain.
148-
- Support other protocol based STNetTaskQueueHandler, e.g. STNetTaskQueueHandler for ProtocolBuffers.
166+
- Detailed documentation for STNetTaskQueue, STNetTask, STNetTaskChain.
Collapse file

‎STNetTaskQueue/STHTTPNetTask.h‎

Copy file name to clipboardExpand all lines: STNetTaskQueue/STHTTPNetTask.h
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ typedef NS_ENUM(NSUInteger, STHTTPNetTaskResponseType) {
3939
- (STHTTPNetTaskResponseType)responseType;
4040
- (NSDictionary *)parameters;
4141
- (NSDictionary *)datas;
42-
- (void)didResponseJSON:(NSDictionary *)json;
42+
- (void)didResponseDictionary:(NSDictionary *)dictionary;
43+
- (void)didResponseArray:(NSArray *)array;
4344
- (void)didResponseString:(NSString *)string;
4445
- (void)didResponseData:(NSData *)data;
4546

Collapse file

‎STNetTaskQueue/STHTTPNetTask.m‎

Copy file name to clipboardExpand all lines: STNetTaskQueue/STHTTPNetTask.m
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ - (NSDictionary *)parameters
4141
- (void)didResponse:(id)response
4242
{
4343
if ([response isKindOfClass:[NSDictionary class]]) {
44-
[self didResponseJSON:response];
44+
[self didResponseDictionary:response];
45+
}
46+
else if ([response isKindOfClass:[NSArray class]]) {
47+
[self didResponseArray:response];
4548
}
4649
else if ([response isKindOfClass:[NSString class]]) {
4750
[self didResponseString:response];
@@ -54,7 +57,12 @@ - (void)didResponse:(id)response
5457
}
5558
}
5659

57-
- (void)didResponseJSON:(NSDictionary *)json
60+
- (void)didResponseDictionary:(NSDictionary *)dictionary
61+
{
62+
63+
}
64+
65+
- (void)didResponseArray:(NSArray *)array
5866
{
5967

6068
}
Collapse file

‎STNetTaskQueueExample/STNetTaskQueueExample/STOpenWeatherNetTask.m‎

Copy file name to clipboardExpand all lines: STNetTaskQueueExample/STNetTaskQueueExample/STOpenWeatherNetTask.m
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ - (NSUInteger)maxRetryCount
2525
return 3; // Retry after error occurs
2626
}
2727

28+
- (BOOL)shouldRetryForError:(NSError *)error
29+
{
30+
return YES; // Retry for all kinds of errors
31+
}
32+
2833
- (NSDictionary *)parameters
2934
{
3035
NSLog(@"Pack request parameters");
Collapse file

‎STNetTaskQueueTest/STNetTaskQueueTest/STTestGetNetTask.m‎

Copy file name to clipboardExpand all lines: STNetTaskQueueTest/STNetTaskQueueTest/STTestGetNetTask.m
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ - (NSString *)uri
2020
return [NSString stringWithFormat:@"posts/%d", self.id];
2121
}
2222

23-
- (void)didResponseJSON:(NSDictionary *)json
23+
- (void)didResponseDictionary:(NSDictionary *)dictionary
2424
{
25-
_post = json;
25+
_post = dictionary;
2626
}
2727

2828
@end
Collapse file

‎STNetTaskQueueTest/STNetTaskQueueTest/STTestPatchNetTask.m‎

Copy file name to clipboardExpand all lines: STNetTaskQueueTest/STNetTaskQueueTest/STTestPatchNetTask.m
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ - (NSDictionary *)parameters
2525
return @{ @"title": self.title };
2626
}
2727

28-
- (void)didResponseJSON:(NSDictionary *)json
28+
- (void)didResponseDictionary:(NSDictionary *)dictionary
2929
{
30-
_post = json;
30+
_post = dictionary;
3131
}
3232

3333
@end
Collapse file

‎STNetTaskQueueTest/STNetTaskQueueTest/STTestPostNetTask.m‎

Copy file name to clipboardExpand all lines: STNetTaskQueueTest/STNetTaskQueueTest/STTestPostNetTask.m
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ - (NSDictionary *)parameters
2727
@"userId": @(self.userId) };
2828
}
2929

30-
- (void)didResponseJSON:(NSDictionary *)json
30+
- (void)didResponseDictionary:(NSDictionary *)dictionary
3131
{
32-
_post = json;
32+
_post = dictionary;
3333
}
3434

3535
@end
Collapse file

‎STNetTaskQueueTest/STNetTaskQueueTest/STTestPutNetTask.m‎

Copy file name to clipboardExpand all lines: STNetTaskQueueTest/STNetTaskQueueTest/STTestPutNetTask.m
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ - (NSDictionary *)parameters
2828
@"userId": @(self.userId) };
2929
}
3030

31-
- (void)didResponseJSON:(NSDictionary *)json
31+
- (void)didResponseDictionary:(NSDictionary *)dictionary
3232
{
33-
_post = json;
33+
_post = dictionary;
3434
}
3535

3636
@end

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.