mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-17 08:34:19 +01:00
- 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
26 lines
991 B
TypeScript
26 lines
991 B
TypeScript
import { setupMainThread } from "@tursodatabase/database-browser-common";
|
|
import { tursoWasm } from "./wasm-inline.js";
|
|
|
|
// Next (turbopack) has issues with loading wasm module: https://github.com/vercel/next.js/issues/82520
|
|
// So, we inline wasm binary in the source code in order to avoid issues with loading it from the file
|
|
const __wasmFile = await tursoWasm();
|
|
|
|
export let MainWorker = null;
|
|
|
|
const napiModule = await setupMainThread(__wasmFile, () => {
|
|
const worker = new Worker(new URL('./worker.js', import.meta.url), {
|
|
name: 'turso-database',
|
|
type: 'module',
|
|
})
|
|
MainWorker = worker;
|
|
return worker
|
|
});
|
|
|
|
export default napiModule.exports
|
|
export const Database = napiModule.exports.Database
|
|
export const Opfs = napiModule.exports.Opfs
|
|
export const OpfsFile = napiModule.exports.OpfsFile
|
|
export const Statement = napiModule.exports.Statement
|
|
export const connectDbAsync = napiModule.exports.connectDbAsync
|
|
export const initThreadPool = napiModule.exports.initThreadPool
|