Hi,
Is there any way to declare `rethrows` a function that uses `dispatch_sync`?
For example:
func perform_sync(queue: dispatch_queue_t, block: () throws -> Void) rethrows {
var blockError: ErrorType? = nil
dispatch_sync(queue) {
do {
try block()
} catch {
blockError = error
}
}
if let blockError = blockError {
throw blockError
}
}
The code above has the compiler complain with the message "'rethrows' function may only throw by calling a parameter function".
That's quite unfortunate. If it were possible, one could call this `perform_sync` function without `try`:
try perform_sync(queue) { // try, obviously
try dangerousFunction()
}
perform_sync(queue) { // Look, Ma! No try!
safe_function()
}
Of course, such rethrowing is unsafe: it requires the cooperation of the developer. Well, I'd happily welcome an explicit unsafe construct in the Swift language that would allow me to do that.
Thanks in advance if you have any clue.