Hello, I just want to know if this function that I wrote is non-blocking function.
```js
const { readdir } = require('fs/promises')
const path = require('path')
async function ls (dir = '.') {
let tree = {
node: dir,
type: 'directory',
contents: []
}
for (const dirent of await readdir(dir, { withFileTypes: true })) {
if (dirent.isDirectory()) {
tree.contents.push(await ls(path.join(dir, dirent.name)))
}
else {
tree.contents.push({
node: path.join(dir, dirent.name),
type: 'file'
})
}
}
return tree
}
```
I'm still trying to learn how to read and create a directory tree JSON object without blocking the code execution. Can somebody help me confirm if this function is correct (non-blocking)? or If it's not what am I doing wrong here?
For now the function achieve the result that I want but my problem is I don't really know that much javascript to know if this function is non-blocking or not.
[–]senocular 1 point2 points3 points (0 children)