File size: 497 Bytes
94193b5 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import { AsyncLocalStorage } from 'node:async_hooks';
import { registerContextVFSProvider } from '@/lib/vfs';
import type { VirtualFileSystem } from '@/lib/vfs';
const vfsStorage = new AsyncLocalStorage<VirtualFileSystem>();
export function runWithVFS<T>(vfs: VirtualFileSystem, fn: () => Promise<T>): Promise<T> {
return vfsStorage.run(vfs, fn);
}
export function getContextVFS(): VirtualFileSystem | undefined {
return vfsStorage.getStore();
}
registerContextVFSProvider(getContextVFS);
|