Skip to content

Commit

Permalink
Add interface for Async mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
james-pre committed Nov 12, 2024
1 parent 45562dd commit 7836ea5
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/mixins/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,28 @@ export type AsyncOperation = {
[K in keyof AsyncFSMethods]: [K, ...Parameters<FileSystem[K]>];
}[keyof AsyncFSMethods];

/**
* @internal
*/
export interface Async {
/**
* @internal @protected
*/
_sync?: FileSystem;
queueDone(): Promise<void>;
ready(): Promise<void>;
renameSync(oldPath: string, newPath: string): void;
statSync(path: string): Stats;
createFileSync(path: string, flag: string, mode: number): File;
openFileSync(path: string, flag: string): File;
unlinkSync(path: string): void;
rmdirSync(path: string): void;
mkdirSync(path: string, mode: number): void;
readdirSync(path: string): string[];
linkSync(srcpath: string, dstpath: string): void;
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
}

/**
* Async() implements synchronous methods on an asynchronous file system
*
Expand All @@ -22,29 +44,7 @@ export type AsyncOperation = {
* During loading, the contents of the async file system are preloaded into the synchronous store.
*
*/
export function Async<T extends typeof FileSystem>(
FS: T
): Mixin<
T,
{
/**
* @internal @protected
*/
_sync?: FileSystem;
queueDone(): Promise<void>;
ready(): Promise<void>;
renameSync(oldPath: string, newPath: string): void;
statSync(path: string): Stats;
createFileSync(path: string, flag: string, mode: number): File;
openFileSync(path: string, flag: string): File;
unlinkSync(path: string): void;
rmdirSync(path: string): void;
mkdirSync(path: string, mode: number): void;
readdirSync(path: string): string[];
linkSync(srcpath: string, dstpath: string): void;
syncSync(path: string, data: Uint8Array, stats: Readonly<Stats>): void;
}
> {
export function Async<const T extends typeof FileSystem>(FS: T): Mixin<T, Async> {
abstract class AsyncFS extends FS {
/**
* Queue of pending asynchronous operations.
Expand Down Expand Up @@ -226,3 +226,5 @@ export function Async<T extends typeof FileSystem>(

return AsyncFS;
}

export function asyncPatch<T extends typeof FileSystem>(fs: Mixin<T, Async>) {}

0 comments on commit 7836ea5

Please sign in to comment.