Dexie.spawn()

NOTE: In old version (0.9.8) there was another method Dexie.spawn() with a different meaning. That method has been renamed to Dexie.ignoreTransaction()

Syntax

Dexie.spawn(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.

Table below shows how this maps to ES7 async / await.

Using function*() and yieldUsing async / await
Declare async functionDexie.async(function* () {});async function() {}
Declare+execute functionDexie.spawn(function* () {});(async function() {})()
Await a Promiseyield p;await p;
Declare Promise Generatorfunction* f (){}N/A
Await Promise Generatoryield* fn();N/A

Sample

Dexie.spawn(function* () {
    var db = new Dexie("TestDB");
    db.version(1).stores({foo: ',bar'});
    try {
        yield Dexie.delete("TestDB");
        yield db.open();
        yield db.foo.add({bar: "foobar"}, 1);
        var items = yield db.foo.toArray();
        console.log(items.length);
    } finally {
        db.close();
    }
}).catch(e => console.error(e));

See Also

Dexie.async()

Table of Contents