Skip to content

Commit 0c4de54

Browse files
committed
Add examples for async calls
1 parent 098a109 commit 0c4de54

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,32 @@ If `Promise` is defined globally, asynchronous functions return a promise if no
6666

6767
If you want to use promises in environments that don't provide the global `Promise` constructor, use a promise polyfill like [es6-promise](https://www.npmjs.com/package/es6-promise) or inject a ES6-compatible promise implementation like [bluebird](https://www.npmjs.com/package/bluebird) into the global scope.
6868

69+
**Examples**
70+
71+
```js
72+
// Node-style callbacks
73+
db.createDatabase('mydb', function (err, info) {
74+
if (err) console.error(err.stack);
75+
else {
76+
// database created
77+
}
78+
});
79+
80+
// Using promises with ES2015 arrow functions
81+
db.createDatabase('mydb')
82+
.then(info => {
83+
// database created
84+
}, err => console.error(err.stack));
85+
86+
// Using ES2016 "async/await" syntax
87+
try {
88+
let info = await db.createDatabase('mydb');
89+
// database created
90+
} catch (err) {
91+
console.error(err.stack);
92+
}
93+
```
94+
6995
## Database API
7096

7197
### new Database

0 commit comments

Comments
 (0)