@samitouri / QOSami-HFS / commits / 3b19a06e

avoid wasting resources on disconnected sockets

Massimo Melina committed Apr 9, 2026 at 20:23 UTC 3b19a06ecc9fb0c28c190f15a574a2c0d1975260
1 file changed +9 -5
src/vfs.ts
+9 -5
@@ -343,6 +343,7 @@ export async function* walkNode(parent: VfsNode, {
343 const maskApplier = parentMaskApplier(parent)
344 const visitLater: any = []
345 const childrenWorking = parent.children?.length && Promise.all(parent.children.map(async child => {
346 + if (ctx?.isAborted()) return
347 const nodeName = getNodeName(child)
348 const name = prefixPath + nodeName
349 taken?.add(normalizeFilename(name))
@@ -369,10 +370,8 @@ export async function* walkNode(parent: VfsNode, {
370
371 try {
372 await walkDir(source, { depth, ctx, hidden: showHiddenFiles.get(), parallelizeRecursion }, async entry => {
372 - if (ctx?.isAborted()) {
373 - stream.push(null)
373 + if (ctx?.isAborted())
374 return null
375 - }
375 if (usingDescriptIon() && (entry.name === DESCRIPT_ION || entry.name === DESCRIPT_ION_ALT))
376 return
377 const {path} = entry // this path is not the original deprecated property: we are overwriting/reusing it
@@ -403,8 +402,11 @@ export async function* walkNode(parent: VfsNode, {
402 finally {
403 await childrenWorking
404 for (const [item, name] of visitLater)
406 - for await (const x of walkNode(item, { depth: depth - 1, prefixPath: name + '/', ctx, requiredPerm, onlyFolders, onlyFiles, parallelizeRecursion }))
405 + for await (const x of walkNode(item, { depth: depth - 1, prefixPath: name + '/', ctx, requiredPerm, onlyFolders, onlyFiles, parallelizeRecursion })) {
406 + if (ctx?.isAborted())
407 + return stream.push(null)
408 stream.push(x)
409 + }
410 stream.push(null)
411 }
412
@@ -423,8 +425,10 @@ export async function* walkNode(parent: VfsNode, {
425 })
426
427 // must use a stream to be able to work with the callback-based mechanism of walkDir, but Readable is not typed so we wrap it with a generator
426 - for await (const item of stream)
428 + for await (const item of stream) {
429 + if (ctx?.isAborted()) return
430 yield item as VfsNode
431 + }
432 }
433
434 export function masksCouldGivePermission(masks: Masks | undefined, perm: keyof VfsPerms): boolean {