aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/md/docs/0xjs/1.0.1/async.md
diff options
context:
space:
mode:
Diffstat (limited to 'packages/website/md/docs/0xjs/1.0.1/async.md')
-rw-r--r--packages/website/md/docs/0xjs/1.0.1/async.md31
1 files changed, 31 insertions, 0 deletions
diff --git a/packages/website/md/docs/0xjs/1.0.1/async.md b/packages/website/md/docs/0xjs/1.0.1/async.md
new file mode 100644
index 000000000..bd5ae9d8a
--- /dev/null
+++ b/packages/website/md/docs/0xjs/1.0.1/async.md
@@ -0,0 +1,31 @@
+0x packages are promise-based libraries. 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 {
+ const signature = await signatureUtils.ecSignOrderHashAsync(
+ providerEngine,
+ orderHashHex,
+ maker,
+ SignerType.Default,
+ );
+} catch (error) {
+ console.log('Caught error: ', error);
+}
+```
+
+_Promise syntax:_
+
+```javascript
+signatureUtils
+ .ecSignOrderHashAsync(providerEngine, orderHashHex, maker, SignerType.Default)
+ .then(function(signature) {
+ console.log(signature);
+ })
+ .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.