Created
September 29, 2015 20:26
-
-
Save abbeyjackson/88514d0797c40d176e92 to your computer and use it in GitHub Desktop.
synchronous asynchronous background main thread and queue (usually just use "queue" as variable name, descriptive names below only for clarity)
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
// get global queue | |
dispatch_queue_t globalQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); | |
// create serial background queue | |
dispatch_queue_t newQueue = dispatch_queue_create("com.domain.app.queuename", 0); | |
// dispatch asynchronously to a specific thread | |
dispatch_async(queueName, ^{ | |
// the slow stuff to be done in the background | |
}); | |
// dispatch synchronously to a specific thread | |
dispatch_sync(queueName, ^{ | |
// synchronous stuff | |
}); | |
// to use the main queue | |
dispatch_async(dispatch_get_main_queue(), ^{ ... | |
dispatch_sync(dispatch_get_main_queue(), ^{ ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment