0

I am integrating some Swift code with some external C library, whose source code is unavailable. I can easily call the C function I need, but sometimes the function gets stuck for reasons I cannot predict. What I would like to do is 1) call the function, 2) get the result if it arrives within, say, 10 seconds, 3) if the timeout passes, "kill" the call to the C function and continue normal program execution.

In other answers on SO (like Timeout function after 10 seconds Swift/iOS and dispatch_async timeout method call) the stopper owned the code to be stopped, but here I don't, so I'm not sure how to proceed.

Community
  • 1
  • 1
Maiaux
  • 965
  • 9
  • 19
  • do you have access to the kill function in the external library? – Russell Jan 31 '17 at 12:14
  • @Russell I'm not sure what you mean. I just have the .a library file with the corresponding .h, which lists the header of the function I call. I don't think the author of the library has made any kill function available for my purpose. So the "killing" needs to happen at some other level, if at all possible – Maiaux Jan 31 '17 at 12:23
  • well, that's a shame :-( You can certainly stop waiting for the response within your code, and reinitiate the call, but doesn't look like you can do much if you don't have access to externalFunction.KillMeNow() – Russell Jan 31 '17 at 12:25

0 Answers0