vfs_async_read
Pure-Luau wrapper that grafts a yielding `vfs.read` over the engine's sync `vfs.read` binding. The `vfs` API module (`modules/api/engine/vfs`) calls `M.installInto(vfs)` on itself as it loads, so every VM holding `vfs` (user VMs and the trusted VM alike) reads through it; user co…
vfs_async_read
Pure-Luau wrapper that grafts a yielding vfs.read over the engine's
sync vfs.read binding. The vfs API module
(modules/api/engine/vfs) calls M.installInto(vfs) on itself as it
loads, so every VM holding vfs (user VMs and the trusted VM alike)
reads through it; user code never requires this module directly: it
just calls vfs.read(path) and the wrapper handles cache misses by
yielding the running coroutine until the bytes resolve.
Exports
M.installInto(vfs: VfsNamespace): replacevfs.read(andvfs.readBounded) with the yielding wrapper. No-op when the target lacksreadandreadAsyncas functions.M.CANNOT_WAIT:"VFS_READ_CANNOT_WAIT", the code a read raises when it names a known file whose bytes have not arrived and the reading code cannot yield.
Types:
VfsNamespace = { read?, readAsync?, readBounded? }: the engine'svfsglobal shape.
Usage
-- The `vfs` API module installs the wrapper onto itself as it loads:
require("@builtin::modules.vfs_async_read").installInto(vfs)
-- After install, every `vfs.read` call yields on cache miss:
local bytes = vfs.read("/zero/source/some.asset")
Where a read can wait
- On a miss the wrapper schedules
vfs.readAsync(path, opts), which firesBlobProvider::fetchunder the hood, andtask.awaits the promise. The resolved value can still benilif the path isn't in the manifest at all. - Waiting takes a yield, so it happens where
coroutine.isyieldable()is true: a task, the component hooks the engine runs on a coroutine (awake,start,update,fixedUpdate,onEnable,onOwnerChanged,onSyncReceived), a replicated event's handlers, and a world or scene entrypoint's hooks. - Where it is false (
onDisable,onDestroy,onPropertyChanged, a received synced-function call, avfs.watchcallback, a module's top level whilerequireruns it, a metamethod, atable.sortcomparator, a VM's main thread) a miss the engine's read answersnil, "pending"for (a filevfs.existsknows that is no directory and whose bytes can still arrive, a render surface being captured) raisesVFS_READ_CANNOT_WAIT: vfs.read("<path>") ..., naming the path and the places it can be read from. Every other miss answers nil there as everywhere else. installIntois idempotent in the trivial sense: calling it twice re-wrapsvfs.readaround the already-wrapped function, which is fine but pointless.
Scoped to this part · feeds back into the world's score.