开发者

NSThread calling threading delegate function

开发者 https://www.devze.com 2022-12-21 09:27 出处:网络
I am using a framework to get information from the network. The pr开发者_运维技巧oblem is the function I\'m using to get the information is threaded (ie. it gives information through a didFinish selec

I am using a framework to get information from the network. The pr开发者_运维技巧oblem is the function I'm using to get the information is threaded (ie. it gives information through a didFinish selector, not the actual function as the return value).

I want to create a separate NSThread that uses this threaded function. The problem is if I detach a thread, it won't wait for the information from this threaded function (and it doesn't know when the information is sent back).

Is there a way to fix this situation? In a nutshell, I want to turn an asynchronous function into a synchronous function.


You'll want to read up on NSRunLoop and the Threading Programming Guide

I think the basic approach will be something like this:

  • In your detached thread main body
    • set yourself as a custom input source to the runloop
    • while your state is not done, run the runloop
  • In didFinish:
    • set some state that says you're done
    • tell the runloop that the input source (yourself) fired
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号