Skip to content
This repository was archived by the owner on Oct 18, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions MPFastDispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
autoreleasepool {} \
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND,0),BLOCK); \

#define mainthread(BLOCK) \
autoreleasepool {} \
if ([NSThread isMainThread]) BLOCK(); \
else dispatch_async(dispatch_get_main_queue(),BLOCK); \

#define sem(TAG, VAL) \
autoreleasepool {} \
__block dispatch_semaphore_t __sem##TAG = \
Expand Down
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ Import the class in your prefix:

@once(BLOCK) //"dispatch_once" shorthand
@after(SECONDS,BLOCK) //"dispatch_after" shorthand
@mainqueue(BLOCK) //Executes a block on the main queue
@mainqueue(BLOCK) //Executes a block asynchronously on the main queue
@backgroundqueue(BLOCK) // Executes a block on the global background queue
@mainthread(BLOCK) //Executes a block on the main thread

@sem(TAG,VAL) //Creates a semaphore named "__sem##TAG" with value "VAL"
@sem_signal(TAG) //Increments value of semaphore named "__sem##TAG"
Expand Down Expand Up @@ -53,6 +54,24 @@ With **MPFastDispatch** you can do:
CODE
})

##Excute a block on the main thread

To excute a block on the main thread, you would do...

if ([NSThread isMainThread]) {
CODE
} else {
dispatch_async(dispatch_get_main_queue(), ^{
CODE
});
}

With **MPFastDispatch** you can do:

@mainthread(^{
CODE
})

##Dispatch a block once

To dispatch a block once you would do...
Expand Down