Permalink
Browse files

Introducing `RCTAssertUIManagerQueue()`

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 2a984326b0f70d4f4f5577888a962a642ad5dab6
Showing with 23 additions and 2 deletions.
  1. +2 −2 React/Base/RCTAssert.h
  2. +11 −0 React/Modules/RCTUIManager.h
  3. +10 −0 React/Modules/RCTUIManager.m
View
@@ -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
@@ -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.
@@ -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();

0 comments on commit 2a98432

Please sign in to comment.