docs: FAQ document

Question on nature of async/sync calls in different environments
This commit is contained in:
Oskar Thorén 2017-08-15 12:53:25 +02:00 committed by Roman Volosovskyi
parent a93cb0b1d1
commit 6dafd137dc
1 changed files with 25 additions and 0 deletions

25
doc/faq.md Normal file
View File

@ -0,0 +1,25 @@
# FAQ
## Why do we use async JS calls in RN but sometimes sync calls for bots?
(Based on answer by @roma in Slack on August 15, 2017)
Different JS environments have different capabilities. In general we want to use async.
**React Native**
1) RN doesnt support sync http calls (thats why we didnt use sync calls with web3 when we used http provider)
2) RN doesnt allow to make sync calls to native modules, currently we are calling CallRPC through native modules, thats why calls can be only async
**Dapps**
Dapps are running in webview env which supports sync calls in some cases (only android), but we dont support sync calls for iOS, that will not work. Mostly any call to web3 causes http request, so using sync call is a bad idea in one threaded env, in any case. So i wouldnt use it in dapps.
**Bots in Otto VM**
During the last year both sync and async calls were handled by the same function and tbh that was sync call with only difference: in case when we pass callback it was called instead of returning the value. But the call was blocking. Im not sure if it was implemented, but there was an issues about making async calls in otto really async.
**Summary**
- Both sync and async calls are available in otto
- Only async in rn
- Only async in iOS webview
- Both async/sync in Android webview