ios - Why AFNetworking POST Multi-Part Request has to sync run on main queue? -
i check afnetworking codes post multi-part request , find surprise has sync run on main queue,
- (bool)transitiontonextphase { if (![[nsthread currentthread] ismainthread]) { dispatch_sync(dispatch_get_main_queue(), ^{ [self transitiontonextphase]; }); return yes; } ...
this called when create afhttpbodypart post multi-part request
[manager post:@"http://example.com/resources.json" parameters:parameters constructingbodywithblock:^(id<afmultipartformdata> formdata) { [formdata appendpartwithfileurl:filepath name:@"image" error:nil]; } success:^(afhttprequestoperation *operation, id responseobject) { ... } failure:^(afhttprequestoperation *operation, nserror *error) { ... }];
it asked , answered @ github issue #2006 "i think that's there main thread used synchronization point. (to ensure operations happen in correct order, if they're on different threads.)..."
i can understand operations need run in serial order, why in main queue ? can't dedicated queue it?
i added question , relatively easy way reproduce deadlock issue #2481
i can imagine problems scheduling nsinputstream
(see bit later in same routine) on "current" run loop if you're on background thread. can't schedule timers, connections, streams, etc., on background thread without keeping run loop alive somehow (cf. networkrequestthread
). also, there might subtle issues input streams provided app developer (via appendpartwithinputstream
) expecting input stream used main thread, too.
i suspect mattt concluded going lot of work synchronize behavior on thread other main thread. furthermore, there's little benefit moving off main thread (given 1 should never block main thread, anyway).
but should create own issue , ask author directly.
Comments
Post a Comment