Updated docs for next

This commit is contained in:
Website Deployment Script
2017-06-15 11:00:50 +00:00
parent 794775fe0e
commit e0d9f33e2e
+1 -1
View File
@@ -77,7 +77,7 @@ CalendarManager<span class="token punctuation">.</span><span class="token functi
<span class="token function">updateEvents</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></div><h2><a class="anchor" name="threading"></a>Threading <a class="hash-link" href="docs/native-modules-ios.html#threading">#</a></h2><p>The native module should not have any assumptions about what thread it is being called on. React Native invokes native modules methods on a separate serial GCD queue, but this is an implementation detail and might change. The <code>- (dispatch_queue_t)methodQueue</code> method allows the native module to specify which queue its methods should be run on. For example, if it needs to use a main-thread-only iOS API, it should specify this via:</p><div class="prism language-objectivec"><span class="token operator">-</span> <span class="token punctuation">(</span>dispatch_queue_t<span class="token punctuation">)</span>methodQueue
<span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token function">dispatch_get_main_queue<span class="token punctuation">(</span></span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></div><p>Similarly, if an operation may take a long time to complete, the native module should not block and can specify it&#x27;s own queue to run operations on. For example, the <code>RCTAsyncLocalStorage</code> module creates it&#x27;s own queue so the React queue isn&#x27;t blocked waiting on potentially slow disk access:</p><div class="prism language-objectivec"><span class="token operator">-</span> <span class="token punctuation">(</span>dispatch_queue_t<span class="token punctuation">)</span>methodQueue
<span class="token punctuation">}</span></div><p>Similarly, if an operation may take a long time to complete, the native module should not block and can specify it&#x27;s own queue to run operations on. For example, the <code>RCTAsyncLocalStorage</code> module creates its own queue so the React queue isn&#x27;t blocked waiting on potentially slow disk access:</p><div class="prism language-objectivec"><span class="token operator">-</span> <span class="token punctuation">(</span>dispatch_queue_t<span class="token punctuation">)</span>methodQueue
<span class="token punctuation">{</span>
<span class="token keyword">return</span> <span class="token function">dispatch_queue_create<span class="token punctuation">(</span></span><span class="token string">&quot;com.facebook.React.AsyncLocalStorageQueue&quot;</span><span class="token punctuation">,</span> DISPATCH_QUEUE_SERIAL<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></div><p>The specified <code>methodQueue</code> will be shared by all of the methods in your module. If <em>just one</em> of your methods is long-running (or needs to be run on a different queue than the others for some reason), you can use <code>dispatch_async</code> inside the method to perform that particular method&#x27;s code on another queue, without affecting the others:</p><div class="prism language-objectivec"><span class="token function">RCT_EXPORT_METHOD<span class="token punctuation">(</span></span>doSomethingExpensive<span class="token punctuation">:</span><span class="token punctuation">(</span>NSString <span class="token operator">*</span><span class="token punctuation">)</span>param callback<span class="token punctuation">:</span><span class="token punctuation">(</span>RCTResponseSenderBlock<span class="token punctuation">)</span>callback<span class="token punctuation">)</span>