-
-
Notifications
You must be signed in to change notification settings - Fork 641
Dexie.async()
David Fahlander edited this page Mar 15, 2016
·
15 revisions
var myAsyncFunction = Dexie.async(function* () {
// Function body goes here.
// To await, use the yield keyword.
});
Makes it possible to use async functions with modern browsers (Chrome, Firefox, Opera and Edge) without the need of a transpiler.
Table below shows how this maps to ES7 async / await.
+--------------------------------+--------------------------+
| Using function*() and yield | Using async / await |
+--------------------------+--------------------------------+--------------------------+
| Declare async function | Dexie.async(function* () {}); | async function() {} |
+--------------------------+--------------------------------+--------------------------+
| Declare+execute function | Dexie.spawn(function* () {}); | (async function() {})() |
+--------------------------+--------------------------------+--------------------------+
| await a Promise | yield p; | await p; |
+--------------------------+--------------------------------+--------------------------+
| Declare Promise Generator| function* f (){} | N/A |
+--------------------------+-----------------------------------------------------------+
| await Promise Generator | yield* f(); | N/A |
+--------------------------+-----------------------------------------------------------+
db.delete().then(function() {
console.log("Database successfully deleted");
}).catch(function (err) {
console.error("Could not delete database");
}).finally(function() {
// Do what should be done next...
});
Dexie.js - minimalistic and bullet proof indexedDB library