kriszyp / lmdb-js

Simple, efficient, ultra-fast, scalable data store wrapper for LMDB
Other
505 stars 41 forks source link

Wrapping lmdb.open and returning the environment result in an async function returns a boolean instead of the environment reference #129

Closed kylebernhardy closed 2 years ago

kylebernhardy commented 2 years ago

Starting in lmdb-js v 2.1.1 if you wrap the results of lmdb.open in an async function the returned value is a Boolean of true instead of the environment reference.

This will cause the bad behavior:

'use strict';

const lmdb = require('lmdb');

async function createEnv() {

    let env_init = {
        "path": './data',
    };
    let my_env = lmdb.open(env_init);
    console.log(my_env.constructor.name);
    return my_env;
}

(async ()=> {
    let my_env = await createEnv();
    console.log(my_env.constructor.name);
})();

Result from this is:

LMDBStore

Boolean

This synchronous code works fine:

'use strict';

const lmdb = require('lmdb');

function createEnv() {

    let env_init = {
        "path": './data',
    };
    let my_env = lmdb.open(env_init);
    console.log(my_env.constructor.name);
    return my_env;
}

(async ()=> {
    let my_env = createEnv();
    console.log(my_env.constructor.name);
})();

Returns:

LMDBStore

LMDBStore
kriszyp commented 2 years ago

Should be fixed in v2.1.6

kylebernhardy commented 2 years ago

Thanks! it works great.