Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save valentebruno/9a77d099823d18ba30f9 to your computer and use it in GitHub Desktop.
Save valentebruno/9a77d099823d18ba30f9 to your computer and use it in GitHub Desktop.
// Dispatch
//
// Usage:
// Async dispatch to main queue
// -->block
// Async dispatch to queue
// queue --> block
// Sync dispatch to main queue
// -->|block
// Sync dispatch to queue
// queue -->| block
//
operator prefix --> {}
operator infix --> {}
operator prefix -->| {}
operator infix -->| {}
@prefix func --> (block:(Void->Void)?) {
dispatch_get_main_queue() --> block
}
@infix func --> (queue:dispatch_queue_t, block:(Void->Void)?) {
if block {
dispatch_async(queue, block!)
}
}
@prefix func -->| (block:(Void->Void)?) {
dispatch_get_main_queue() -->| block
}
@infix func -->| (queue:dispatch_queue_t, block:(Void->Void)?) {
if block {
dispatch_sync(queue, block!)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment