Skip to content

Dexie.async()

David Fahlander edited this page Mar 15, 2016 · 15 revisions

Syntax

var myAsyncFunction = Dexie.async(function* () {
    // Function body goes here.
    // To await, use the yield keyword.
});

Return Value

Promise

Description

Makes it possible to use async functions with modern browsers (Chrome, Firefox, Opera and Edge) without the need of a transpiler.

+----------------------------------+--------------------------+
| ES6 syntax                       | ES7 equivalent syntax    |
+----------------------------------+--------------------------+
| Dexie.async(function* () {});    | async function() {}      |
+----------------------------------+--------------------------+
| Dexie.spawn(function* () {});    | (async function() {})()  |
+----------------------------------+--------------------------+
| await p;                         | yield p;                 |
+-------------------------------------------------------------+

Sample

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...
});
Clone this wiki locally