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.