mirror of
https://github.com/TermiT/Flycut.git
synced 2025-09-29 00:14:38 +08:00
Use a DispatchSemaphore for blocking rather than a DispatchQueue.
This commit is contained in:
parent
99d471f46a
commit
adad531327
1 changed files with 4 additions and 5 deletions
|
@ -19,7 +19,7 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
|
|||
var rememberedSyncClippings:Bool = false
|
||||
|
||||
let pasteboardInteractionQueue = DispatchQueue(label: "com.Flycut.pasteboardInteractionQueue")
|
||||
let alertHandlingQueue = DispatchQueue(label: "com.Flycut.alertHandlingQueue")
|
||||
let alertHandlingSemaphore = DispatchSemaphore(value: 0)
|
||||
let defaultsChangeHandlingQueue = DispatchQueue(label: "com.Flycut.defaultsChangeHandlingQueue")
|
||||
|
||||
|
||||
|
@ -239,7 +239,7 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
|
|||
{
|
||||
alertController.addAction(UIAlertAction(title: option as? String, style: .default) { action in
|
||||
selection = action.title
|
||||
self.alertHandlingQueue.resume()
|
||||
self.alertHandlingSemaphore.signal()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -250,13 +250,12 @@ class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSour
|
|||
|
||||
// topController should now be your topmost view controller
|
||||
|
||||
// Transform the asynchronous UIAlertController into a synchronous alert by suspending a GCD serial queue before presenting then placing an empty sync on that queue to block until it is resumed, and resuming after selection. The GCD sync can't complete until the selection resumes the queue.
|
||||
// Transform the asynchronous UIAlertController into a synchronous alert by waiting, after presenting, on a semaphore that is initialized to zero and only signaled in the selection handler.
|
||||
|
||||
alertHandlingQueue.suspend()
|
||||
DispatchQueue.main.async {
|
||||
topController.present(alertController, animated: true)
|
||||
}
|
||||
alertHandlingQueue.sync { } // To wait for queue to resume.
|
||||
alertHandlingSemaphore.wait() // To wait for queue to resume.
|
||||
}
|
||||
|
||||
return selection
|
||||
|
|
Loading…
Add table
Reference in a new issue