aboutsummaryrefslogtreecommitdiffstats
path: root/packages/website/md/docs/0xjs/2.0.0/async.md
blob: c84eebf945af97aaf4544efba180743dcc10b8f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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 web3Wrapper.getAvailableAddressesAsync();
} catch (error) {
    console.log('Caught error: ', error);
}
```

_Promise syntax:_

```javascript
web3Wrapper
    .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.