Skip to content

Commit

Permalink
Introducing RCTAssertUIManagerQueue()
Browse files Browse the repository at this point in the history
Reviewed By: javache

Differential Revision: D4868564

fbshipit-source-id: b9b9f6cf8f31495bb0e82fb60b2402dde460ddb8
  • Loading branch information
shergin authored and facebook-github-bot committed May 8, 2017
1 parent bd00456 commit 2a98432
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions React/Base/RCTAssert.h
Expand Up @@ -85,13 +85,13 @@ typedef void (^RCTFatalHandler)(NSError *error);
* Convenience macro for asserting that we're running on main queue.
*/
#define RCTAssertMainQueue() RCTAssert(RCTIsMainQueue(), \
@"This function must be called on the main thread")
@"This function must be called on the main queue")

/**
* Convenience macro for asserting that we're running off the main queue.
*/
#define RCTAssertNotMainQueue() RCTAssert(!RCTIsMainQueue(), \
@"This function must not be called on the main thread")
@"This function must not be called on the main queue")

/**
* Deprecated, do not use
Expand Down
11 changes: 11 additions & 0 deletions React/Modules/RCTUIManager.h
Expand Up @@ -25,6 +25,17 @@ RCT_EXTERN dispatch_queue_t RCTGetUIManagerQueue(void);
*/
RCT_EXTERN char *const RCTUIManagerQueueName;

/**
* Check if we are currently on UIManager queue.
*/
RCT_EXTERN BOOL RCTIsUIManagerQueue(void);

/**
* Convenience macro for asserting that we're running on UIManager queue.
*/
#define RCTAssertUIManagerQueue() RCTAssert(RCTIsUIManagerQueue(), \
@"This function must be called on the UIManager queue")

/**
* Posted right before re-render happens. This is a chance for views to invalidate their state so
* next render cycle will pick up updated views and layout appropriately.
Expand Down
10 changes: 10 additions & 0 deletions React/Modules/RCTUIManager.m
Expand Up @@ -345,6 +345,16 @@ dispatch_queue_t RCTGetUIManagerQueue(void)
return shadowQueue;
}

BOOL RCTIsUIManagerQueue()
{
static void *queueKey = &queueKey;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
dispatch_queue_set_specific(RCTGetUIManagerQueue(), queueKey, queueKey, NULL);
});
return dispatch_get_specific(queueKey) == queueKey;
}

- (dispatch_queue_t)methodQueue
{
return RCTGetUIManagerQueue();
Expand Down

0 comments on commit 2a98432

Please sign in to comment.