Skip to content

Commit

Permalink
Remove async
Browse files Browse the repository at this point in the history
  • Loading branch information
carlopi committed Jan 15, 2025
1 parent b4dbf64 commit 2dd6926
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
33 changes: 26 additions & 7 deletions packages/duckdb-wasm/src/bindings/bindings_base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,20 +476,21 @@ 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);
this.registerFileHandleAsync(filePath, handle, DuckDBDataProtocol.BROWSER_FSACCESS, true);
}
}
return;
}
throw new Error(`prepareDBFileHandle: unsupported protocol ${protocol}`);
}
/** Register a file object URL */
public async registerFileHandle<HandleType>(
/** Prepare a file object URL */
public async prepareFileHandleAsync<HandleType>(
name: string,
handle: HandleType,
protocol: DuckDBDataProtocol,
directIO: boolean,
): Promise<void> {
): Promise<HandleType> {
console.warn("prepareFileHandleAsync in base");
if (protocol === DuckDBDataProtocol.BROWSER_FSACCESS) {
if( handle instanceof FileSystemSyncAccessHandle ){
// already a handle is sync handle.
Expand All @@ -512,6 +513,27 @@ export abstract class DuckDBBindingsBase implements DuckDBBindings {
}
}
}
return handle;
}
/** Register a file object URL async */
public async registerFileHandleAsync<HandleType>(
name: string,
handle: HandleType,
protocol: DuckDBDataProtocol,
directIO: boolean,
): Promise<void> {
console.warn("registerFileHandleAsync in base");
var handle_inner = await this.prepareFileHandleAsync(name, handle, protocol, directIO);
this.registerFileHandle(name, handle_inner, protocol, directIO);
}
/** Register a file object URL */
public registerFileHandle<HandleType>(
name: string,
handle: HandleType,
protocol: DuckDBDataProtocol,
directIO: boolean,
): void {
console.warn("registerFileHandle in base");
const [s, d, n] = callSRet(
this.mod,
'duckdb_web_fs_register_file_url',
Expand All @@ -523,9 +545,6 @@ export abstract class DuckDBBindingsBase implements DuckDBBindings {
}
dropResponseBuffers(this.mod);
globalThis.DUCKDB_RUNTIME._files = (globalThis.DUCKDB_RUNTIME._files || new Map()).set(name, handle);
if (globalThis.DUCKDB_RUNTIME._preparedHandles?.[name]) {
delete globalThis.DUCKDB_RUNTIME._preparedHandles[name];
}
if (this.pthread) {
for (const worker of this.pthread.runningWorkers) {
worker.postMessage({
Expand Down
14 changes: 13 additions & 1 deletion packages/duckdb-wasm/src/bindings/bindings_interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,24 @@ export interface DuckDBBindings {
registerFileURL(name: string, url: string, proto: DuckDBDataProtocol, directIO: boolean): void;
registerFileText(name: string, text: string): void;
registerFileBuffer(name: string, buffer: Uint8Array): void;
registerFileHandle<HandleType>(
registerFileHandleAsync<HandleType>(
name: string,
handle: HandleType,
protocol: DuckDBDataProtocol,
directIO: boolean,
): Promise<void>;
prepareFileHandleAsync<HandleType>(
name: string,
handle: HandleType,
protocol: DuckDBDataProtocol,
directIO: boolean,
): Promise<HandleType>;
registerFileHandle<HandleType>(
name: string,
handle: HandleType,
protocol: DuckDBDataProtocol,
directIO: boolean,
) : void;
prepareDBFileHandle(path: string, protocol: DuckDBDataProtocol): Promise<void>;
globFiles(path: string): WebFile[];
dropFile(name: string): void;
Expand Down
2 changes: 1 addition & 1 deletion packages/duckdb-wasm/src/parallel/worker_dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down

0 comments on commit 2dd6926

Please sign in to comment.