fs: add async glob and make it (async) iteratable#48594
fs: add async glob and make it (async) iteratable#48594rluvaton wants to merge 9 commits intonodejs:mainfrom
Conversation
| } | ||
| let val; | ||
| try { | ||
| val = await readdir(path, { __proto__: null, withFileTypes: true }); |
There was a problem hiding this comment.
and yield the results or just opendir? because yielding the result will cause incomplete cache
There was a problem hiding this comment.
then it probably makes sense to use readdir for the first iteration
There was a problem hiding this comment.
how will it solve the issue? on further iterations we should get from the cache and not use opendir anyway...
There was a problem hiding this comment.
I meant first iteration of the feature
lib/internal/fs/glob.js
Outdated
| children = await this.#cache.readdir(fullpath); | ||
| } | ||
|
|
||
| for (let i = 0; i < children.length; i++) { |
There was a problem hiding this comment.
| children = await this.#cache.readdir(fullpath); | |
| } | |
| for (let i = 0; i < children.length; i++) { | |
| children = this.#cache.opendir(fullpath); | |
| } | |
| for await (let i = 0; i < children.length; i++) { |
changing to opendir will require this
There was a problem hiding this comment.
doing that we will have incomplete cache
lib/internal/fs/glob.js
Outdated
| for (const index of pattern.indexes) { | ||
| // For each child, check potential patterns | ||
| if (this.#cache.seen(entryPath, pattern, index) || this.#cache.seen(entryPath, pattern, index + 1)) { | ||
| // TODO - fix this not finish the addSubPatterns |
There was a problem hiding this comment.
@MoLow any JS trick to finish the called generator?
There was a problem hiding this comment.
test the return value of addFromChildren
for (const entry of children) {
const result = this.addFromChildren(entry, path, fullpath, pattern, last, isLast);
if (result === null) {
return;
}
yield result;
}There was a problem hiding this comment.
addFromChildren is a generator by itself so I need to get the value from it so I thought if you have another way
lib/internal/fs/glob.js
Outdated
| this.#cache.addToStatCache(join(fullpath, entry.name), entry); | ||
| const children = await this.#cache.readdir(fullpath); | ||
|
|
||
| for (const entry of children) { |
There was a problem hiding this comment.
dont use for of, since the prototype can be tampered
There was a problem hiding this comment.
can I use for of for going over generator or do I need to handle all the state by myself?
Extracted from:
Cc @MoLow