kriszyp / lmdb-js

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

Problems using lmdb-js with bun #259

Open larsw opened 11 months ago

larsw commented 11 months ago

Hi,

I'm trying to use lmdb-js with bun (1.0.7) but it just hangs (as far as I can see, it's able to create/open the database, but not doing put/get with or without a transaction.

Is there any way I can try to diagnose this further?

larsw commented 11 months ago
import { open } from 'lmdb'; // or require
let myDB = open({
    path: 'my-db',

});

await myDB.put('greeting', { someText: 'Hello, World!' });
console.log(myDB.get('greeting').someText)

await myDB.transaction(() => {
    myDB.put('greeting', { someText: 'Hello, World!' });
    myDB.get('greeting').someText // 'Hello, World!'
    console.log('Hello, World! in tx');
});

Seems like the non-transactional code works, but not the put/get happening in a transaction.

kriszyp commented 11 months ago

Asynchronous transaction callbacks require threadsafe calls, and I believe that has not been fully implemented (correctly) in Bun: https://github.com/oven-sh/bun/issues/158#issuecomment-1126624085

Note that you can still execute multiple puts in the same event turn or same batch and they will be transactionally committed together, it is the async transaction callback that can't function without the NAPI threadsafe call system.