ios - Cancelled requests take a lot of time for a last new request in queue -
i've tried lot of approaches , still can't figure out how resolve issue.
i make url request different parameters , show spinner (async request). need cancel previous request , create new one. there 20 cancelled requests , 1 active last.
the last example i've implemented afnetworking
:
if connectionmanager.sharedinstance.businessoperation != nil { connectionmanager.sharedinstance.businessoperation!.cancel() } let manager = connectionmanager.sharedinstance.businessmanager manager.responseserializer = afjsonresponseserializer() manager.requestserializer = afjsonrequestserializer(writingoptions: .allzeros) var path = connectionmanager.sharedinstance.path + objectpathcomponent.businesses.rawvalue path = path.stringbyaddingpercentescapesusingencoding(nsutf8stringencoding)! nslog("start loading") connectionmanager.sharedinstance.businessoperation = manager.get(path, parameters: params, success: { (operation: afhttprequestoperation!, responseobject: anyobject!) -> void in nslog("loaded") connectionmanager.sharedinstance.businessoperation = nil completionhandler(responseobject) }, failure: { (operation: afhttprequestoperation!, error: nserror!) -> void in if error.code != nsurlerrorcancelled { nslog("business request error") completionhandler(error) } else { nslog("cancelled") } })
that's logs:
2015-07-09 00:48:49.639 [97349:3984410] start loading 2015-07-09 00:48:50.060 [97349:3984504] loaded 2015-07-09 00:48:52.401 [97349:3984410] start loading 2015-07-09 00:48:52.820 [97349:3984505] loaded 2015-07-09 00:49:58.622 [97349:3984410] start loading 2015-07-09 00:50:03.364 [97349:3985559] loaded 2015-07-09 00:50:05.025 [97349:3984410] start loading 2015-07-09 00:50:05.534 [97349:3984410] start loading 2015-07-09 00:50:05.535 [97349:3985555] cancelled 2015-07-09 00:50:06.068 [97349:3984410] start loading 2015-07-09 00:50:06.069 [97349:3985555] cancelled 2015-07-09 00:50:06.546 [97349:3984410] start loading 2015-07-09 00:50:06.546 [97349:3985822] cancelled 2015-07-09 00:50:07.070 [97349:3984410] start loading 2015-07-09 00:50:07.070 [97349:3985558] cancelled 2015-07-09 00:50:09.366 [97349:3984410] start loading 2015-07-09 00:50:09.366 [97349:3985555] cancelled 2015-07-09 00:50:09.875 [97349:3984410] start loading 2015-07-09 00:50:09.876 [97349:3985559] cancelled 2015-07-09 00:50:10.407 [97349:3984410] start loading 2015-07-09 00:50:10.408 [97349:3985822] cancelled 2015-07-09 00:50:10.874 [97349:3984410] start loading 2015-07-09 00:50:10.875 [97349:3985822] cancelled 2015-07-09 00:50:11.344 [97349:3984410] start loading 2015-07-09 00:50:11.344 [97349:3985822] cancelled 2015-07-09 00:50:11.793 [97349:3984410] start loading 2015-07-09 00:50:11.793 [97349:3985559] cancelled 2015-07-09 00:50:12.297 [97349:3984410] start loading 2015-07-09 00:50:12.297 [97349:3985822] cancelled 2015-07-09 00:50:12.800 [97349:3984410] start loading 2015-07-09 00:50:12.800 [97349:3985822] cancelled 2015-07-09 00:50:13.315 [97349:3984410] start loading 2015-07-09 00:50:13.315 [97349:3984505] cancelled 2015-07-09 00:50:14.047 [97349:3984410] start loading 2015-07-09 00:50:14.048 [97349:3984505] cancelled 2015-07-09 00:50:14.603 [97349:3984410] start loading 2015-07-09 00:50:14.604 [97349:3984505] cancelled 2015-07-09 00:50:15.067 [97349:3984410] start loading 2015-07-09 00:50:15.067 [97349:3984505] cancelled 2015-07-09 00:50:15.601 [97349:3984410] start loading 2015-07-09 00:50:15.601 [97349:3985559] cancelled 2015-07-09 00:50:50.896 [97349:3986273] loaded
if take @ first, there 5 sec max delay between 'start loading' , 'loaded'. when lot of requests cancelled, can more 30 sec , depends on how many requests made.
is there way change priority last request? need complete request fastest can queue, think, not allow me this.
will glad hear ideas.
Comments
Post a Comment