This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let operationQueue: OperationQueue = OperationQueue() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| OperationQueue.main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func executeOnMain() { | |
| if !Thread.isMainThread { | |
| DispatchQueue.main.async(execute: {() -> Void in | |
| executeOnMain() | |
| }) | |
| return | |
| } | |
| // do something | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let lock = self | |
| objc_sync_enter(lock) | |
| closure() | |
| objc_sync_exit(lock) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let s = DispatchSemaphore(value: 1) | |
| _ = s.wait(timeout: DispatchTime.distantFuture) | |
| // do something | |
| s.signal() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var m = pthread_mutex_t() | |
| pthread_mutex_lock(&m) | |
| // do something | |
| pthread_mutex_unlock(&m) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let lock = NSLock() | |
| lock.lock() | |
| //do something | |
| lock.unlock() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| operation2.addDependency(operation1) //execute operation1 before operation2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class CustomOperation: Operation { | |
| override func main() { | |
| guard isCancelled == false else { | |
| finish(true) | |
| return | |
| } | |
| // Do something | |
| finish(true) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let operationQueue: OperationQueue = OperationQueue() | |
| operationQueue.addOperations([operation1], waitUntilFinished: false) |