Skip to content

Instantly share code, notes, and snippets.

@abbeyjackson
Created September 29, 2015 20:26
Show Gist options
  • Save abbeyjackson/88514d0797c40d176e92 to your computer and use it in GitHub Desktop.
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)
// 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