aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/md/docs/0xjs/async.md
diff options
context:
space:
mode:
Diffstat (limited to 'packages/website/md/docs/0xjs/async.md')
-rw-r--r--packages/website/md/docs/0xjs/async.md23
1 files changed, 23 insertions, 0 deletions
diff --git a/packages/website/md/docs/0xjs/async.md b/packages/website/md/docs/0xjs/async.md
new file mode 100644
index 000000000..63924c76c
--- /dev/null
+++ b/packages/website/md/docs/0xjs/async.md
@@ -0,0 +1,23 @@
+0x.js is a promise-based library. This means that whenever an asynchronous call is required, the library method will return a native Javascript promise. You can therefore choose between using `promise` or `async/await` syntax when calling our async methods.
+
+*Async/await syntax (recommended):*
+```javascript
+try {
+ var availableAddresses = await zeroEx.getAvailableAddressesAsync();
+} catch (error) {
+ console.log('Caught error: ', error);
+}
+```
+
+*Promise syntax:*
+```javascript
+zeroEx.getAvailableAddressesAsync()
+ .then(function(availableAddresses) {
+ console.log(availableAddresses);
+ })
+ .catch(function(error) {
+ console.log('Caught error: ', error);
+ });
+```
+
+As is the convention with promise-based libraries, if an error occurs, it is thrown. It is the callers responsibility to catch thrown errors and to handle them appropriately.