From 7456b464792fe79b35886f4ff8e534204ae3dbd4 Mon Sep 17 00:00:00 2001 From: Carlo Piovesan Date: Wed, 15 Jan 2025 14:07:43 +0100 Subject: [PATCH] Move back to syncronous function registerFileHandle in DuckDBBindings Iterating on https://github.com/duckdb/duckdb-wasm/pull/1856 --- .../duckdb-wasm/src/bindings/bindings_base.ts | 27 ++++++++++++++++--- .../src/bindings/bindings_interface.ts | 12 +++++++++ .../src/parallel/worker_dispatcher.ts | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/packages/duckdb-wasm/src/bindings/bindings_base.ts b/packages/duckdb-wasm/src/bindings/bindings_base.ts index 84f01c33d..b33524e4f 100644 --- a/packages/duckdb-wasm/src/bindings/bindings_base.ts +++ b/packages/duckdb-wasm/src/bindings/bindings_base.ts @@ -476,20 +476,20 @@ export abstract class DuckDBBindingsBase implements DuckDBBindings { for (const item of list) { const { handle, path: filePath, fromCached } = item; if (!fromCached && handle.getSize()) { - await this.registerFileHandle(filePath, handle, DuckDBDataProtocol.BROWSER_FSACCESS, true); + await this.registerFileHandleAsync(filePath, handle, DuckDBDataProtocol.BROWSER_FSACCESS, true); } } return; } throw new Error(`prepareDBFileHandle: unsupported protocol ${protocol}`); } - /** Register a file object URL */ - public async registerFileHandle( + /** Prepare a file object URL */ + public async prepareFileHandleAsync( name: string, handle: HandleType, protocol: DuckDBDataProtocol, directIO: boolean, - ): Promise { + ): Promise { if (protocol === DuckDBDataProtocol.BROWSER_FSACCESS) { if( handle instanceof FileSystemSyncAccessHandle ){ // already a handle is sync handle. @@ -512,6 +512,25 @@ export abstract class DuckDBBindingsBase implements DuckDBBindings { } } } + return handle; + } + /** Register a file object URL async */ + public async registerFileHandleAsync( + name: string, + handle: HandleType, + protocol: DuckDBDataProtocol, + directIO: boolean, + ): Promise { + const handle_inner = await this.prepareFileHandleAsync(name, handle, protocol, directIO); + this.registerFileHandle(name, handle_inner, protocol, directIO); + } + /** Register a file object URL */ + public registerFileHandle( + name: string, + handle: HandleType, + protocol: DuckDBDataProtocol, + directIO: boolean, + ): void { const [s, d, n] = callSRet( this.mod, 'duckdb_web_fs_register_file_url', diff --git a/packages/duckdb-wasm/src/bindings/bindings_interface.ts b/packages/duckdb-wasm/src/bindings/bindings_interface.ts index 31ccca43b..dcf0fb926 100644 --- a/packages/duckdb-wasm/src/bindings/bindings_interface.ts +++ b/packages/duckdb-wasm/src/bindings/bindings_interface.ts @@ -41,7 +41,19 @@ export interface DuckDBBindings { handle: HandleType, protocol: DuckDBDataProtocol, directIO: boolean, + ): void; + registerFileHandleAsync( + name: string, + handle: HandleType, + protocol: DuckDBDataProtocol, + directIO: boolean, ): Promise; + prepareFileHandleAsync( + name: string, + handle: HandleType, + protocol: DuckDBDataProtocol, + directIO: boolean, + ): Promise; prepareDBFileHandle(path: string, protocol: DuckDBDataProtocol): Promise; globFiles(path: string): WebFile[]; dropFile(name: string): void; diff --git a/packages/duckdb-wasm/src/parallel/worker_dispatcher.ts b/packages/duckdb-wasm/src/parallel/worker_dispatcher.ts index 2ebcfd07c..06b81a5b8 100644 --- a/packages/duckdb-wasm/src/parallel/worker_dispatcher.ts +++ b/packages/duckdb-wasm/src/parallel/worker_dispatcher.ts @@ -328,7 +328,7 @@ export abstract class AsyncDuckDBDispatcher implements Logger { break; case WorkerRequestType.REGISTER_FILE_HANDLE: - await this._bindings.registerFileHandle( + await this._bindings.registerFileHandleAsync( request.data[0], request.data[1], request.data[2],