• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How can I get a single threaded network call in ObjC on iOS?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Re: How can I get a single threaded network call in ObjC on iOS?
  • From: Peter Tomaselli <email@hidden>
  • Date: Tue, 28 Jun 2016 17:16:21 -0400

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 28, 2016 at 4:35 PM, Gary L. Wade <email@hidden>
wrote:

> 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 Jun 28, 2016, at 1:16 PM, Jim Adams <email@hidden> wrote:
> >
> > 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, 2016, at 4:11 PM, Gary L. Wade <email@hidden>
> 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 Jun 28, 2016, at 12:52 PM, Jim Adams <email@hidden> 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. I am using NSURLSession and
> NSURLSessionDataTask. I have set the Maximum Concurrent Host number in the
> configuration to 1 but I have seen evidence that there are simultaneous
> requests going up to my servers.
> >>>
> >>> Actually I don’t think they are truly simultaneous, just that the
> completion handler doesn’t finish before the next request goes out. Is
> there a way to make the next request wait until the completion block is
> exited?
> >>>
> >>> My evidence comes from looking in the server logs. I have 3 servers in
> AWS behind an ELB. If I am able to get the cookies back from the server
> before sending the next request then my request will go to the same server
> that the last request went to. If I don’t wait then then the request goes
> to a random server. If I watch the logs I can see the requests come in on
> multiple servers.
> >
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Follow-Ups:
    • Re: How can I get a single threaded network call in ObjC on iOS?
      • From: "Gary L. Wade" <email@hidden>
References: 
 >How can I get a single threaded network call in ObjC on iOS? (From: Jim Adams <email@hidden>)
 >Re: How can I get a single threaded network call in ObjC on iOS? (From: "Gary L. Wade" <email@hidden>)
 >Re: How can I get a single threaded network call in ObjC on iOS? (From: Jim Adams <email@hidden>)
 >Re: How can I get a single threaded network call in ObjC on iOS? (From: "Gary L. Wade" <email@hidden>)

  • Prev by Date: Layout guide-based constraints and hiding the status bar
  • Next by Date: Re: How can I get a single threaded network call in ObjC on iOS?
  • Previous by thread: Re: How can I get a single threaded network call in ObjC on iOS?
  • Next by thread: Re: How can I get a single threaded network call in ObjC on iOS?
  • Index(es):
    • Date
    • Thread