mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 16:44:19 +01:00
move compute to the main thread for browser and node
- now, most of the work is happening on the main thread - for database in browser, we still have dedicated WebWorker - but it is used only for OPFS access and only for that - for syn in browser we still offload sync operations to the WebWorker
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { DatabaseOpts, SqliteError, } from "@tursodatabase/database-common"
|
||||
import { connect as promiseConnect, Database } from "./promise.js";
|
||||
import { connect as nativeConnect, initThreadPool, MainWorker } from "./index-bundle.js";
|
||||
import { Database, connect as promiseConnect } from "./promise.js";
|
||||
import { initThreadPool, MainWorker, connectDbAsync } from "./index-bundle.js";
|
||||
|
||||
/**
|
||||
* Creates a new database connection asynchronously.
|
||||
@@ -10,13 +10,19 @@ import { connect as nativeConnect, initThreadPool, MainWorker } from "./index-bu
|
||||
* @returns {Promise<Database>} - A promise that resolves to a Database instance.
|
||||
*/
|
||||
async function connect(path: string, opts: DatabaseOpts = {}): Promise<Database> {
|
||||
return await promiseConnect(path, opts, nativeConnect, async () => {
|
||||
const init = async () => {
|
||||
await initThreadPool();
|
||||
if (MainWorker == null) {
|
||||
throw new Error("panic: MainWorker is not initialized");
|
||||
}
|
||||
return MainWorker;
|
||||
});
|
||||
};
|
||||
return await promiseConnect(
|
||||
path,
|
||||
opts,
|
||||
connectDbAsync,
|
||||
init
|
||||
);
|
||||
}
|
||||
|
||||
export { connect, Database, SqliteError }
|
||||
|
||||
Reference in New Issue
Block a user