Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-30 Thread Jim Adams
Just to come back around on this, I ended up using the dispatch_suspend and dispatch_resume method. I had previously explored that but I moved the suspend and resume closer to the network call to make the whole thing simpler. I tried using dispatch_group_enter and dispatch_group_leave but that

Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Alex Zavatone
Smarter people that we are have already spent the time to figure it out. Learn the way they did it and profit from their work and experience. There is a benefit to learning how to create the wheel. That time is not now. Learn the wheel that we have. On Jun 28, 2016, at 7:03 PM, Peter

Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Gary L. Wade
When you try to mix synchronous (one request at a time) and asynchronous calls (the task is set up and a completion handler is called after the original set up calls) together like this, you have to start doing lots of extra management across queues. This pattern can apply across other

Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Peter Tomaselli
I have not a lot of Cocoa experience here, so I am legitimately asking this question, no snark intended: what’s the advantage to building a home-made “serial” “queue” as opposed to just using an actual serial operation queue? Haven’t you just described the first few steps one would take were

Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Jerry Krinock
> On 2016 Jun 28, at 13:16, Jim Adams wrote: > > the second request cannot go through until the first request has completed … > with a multi threaded system, I cannot figure out a way to do that. Ideas > appreciated. dispatch_semaphore Documentation is currently here:

Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Gary L. Wade
Based on his desire to do this serially, he would need a serial queue, and he's using asynchronous requests, so succeeding calls from his completion handler with a simple array in queue pattern is simpler than shoehorning it all into dispatch queues. -- Gary L. Wade (Sent from my iPhone)

Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Alex Zavatone
Would a dispatch queue get what he's looking for? On Jun 28, 2016, at 3:11 PM, Gary L. Wade wrote: > The simplest way to do what you're asking is to not send another request > until your completion handler finishes. > -- > Gary L. Wade (Sent from my iPhone) > http://www.garywade.com/ > >> On

Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Jens Alfke
> On Jun 28, 2016, at 12:52 PM, Jim Adams wrote: > > I have an application that has the requirement that the accesses to the > server be single threaded, i.e. the second request cannot go through until > the first request has completed. That’s pretty unusual. I take it

Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Gary L. Wade
That may work, too, but it sure sounds like an awfully heavy way to do it. -- Gary L. Wade (Sent from my iPhone) http://www.garywade.com/ > On Jun 28, 2016, at 2:16 PM, Peter Tomaselli wrote: > > In the past I’ve used NSOperation for this — wrap each request in an async

Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Peter Tomaselli
In the past I’ve used NSOperation for this — wrap each request in an async NSOperation that only signals completion to its queue when its DataTask completion handler is complete. Then you can blast a bunch of them at a serial queue and they will come out serially until they are done. On Tue, Jun

Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Gary L. Wade
Try using a mutex on your array of requests, when adding and removing them, and only pull a request off the array when you're done with your completion handler or when you have nothing in progress such as when you first start. -- Gary L. Wade (Sent from my iPhone) http://www.garywade.com/ > On

Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Daniel Stenmark
I agree with Gary, but if something about your structure makes that difficult, there’s also a queue suspend/resume approach: let queue = dispatch_queue_create("", DISPATCH_QUEUE_SERIAL) dispatch_async(queue) { dispatch_suspend(queue) myFirstNetworkCall({ (let result) in

Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Jim Adams
Unfortunately, with a multi threaded system, I cannot figure out a way to do that. Ideas appreciated. My network calls could come from any thread. I could see putting the request into a queue, but how to I make the completion handler run on that same queue so it remains blocked? > On Jun 28,

Re: How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Gary L. Wade
The simplest way to do what you're asking is to not send another request until your completion handler finishes. -- Gary L. Wade (Sent from my iPhone) http://www.garywade.com/ > On Jun 28, 2016, at 12:52 PM, Jim Adams wrote: > > I have an application that has the requirement

How can I get a single threaded network call in ObjC on iOS?

2016-06-28 Thread Jim Adams
I have an application that has the requirement that the accesses to the server be single threaded, i.e. the second request cannot go through until the first request has completed. I am using NSURLSession and NSURLSessionDataTask. I have set the Maximum Concurrent Host number in the