I'm working on a personal project and ran into the asynchronous nature of NSURLConnection last night. I'm building a library that is going to interface with a restful api. I'm anticipating reusing this library, in both Foundation command line tools as well as Cocoa applications.

Is there a way I can either check if the runloop is available to call the synchronous method if it is, and send a synchronous request if it is not (in the event of being used in a command line tool).

Alternately, is there a way to always use the asynchronous method but force the application to not exit until the async request has finished?

I noticed this but I'd rather not have to put the call to run outside of the library.

Thanks for any help