Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Develop - #1

Open
pini86 wants to merge 3 commits into
mainfrom
develop
Open

pini86 wants to merge 3 commits into
mainfrom
develop

Conversation

@pini86

@pini86 pini86 commented Dec 5, 2022 •

Copy link
Copy Markdown
Owner
  1. Task: https://github.com/AlreadyBored/nodejs-assignments/blob/main/assignments/nodejs-basics/assignment.md
  2. Screenshot: not required
  3. Deploy: not required
  4. Done 05.12.2022 / deadline 06.12.2022
  5. Score: 206 / 206

Self-evaluation:

File system (src/fs)
+6 create.js implemented properly
+10 copy.js implemented properly
+10 rename.js implemented properly
+6 delete.js implemented properly
+6 list.js implemented properly
+6 read.js implemented properly
Command line interface(src/cli)
+6 env.js implemented properly
+6 args.js implemented properly
Modules(src/modules)
+20 cjsToEsm.cjs refactored properly
Hash (src/hash)
+10 calcHash.js implemented properly
Streams (src/streams)
+10 read.js implemented properly
+10 write.js implemented properly
+10 transform.js implemented properly
Zlib (src/zip)
+10 compress.js implemented properly
+10 decompress.js implemented properly
Worker Threads (src/wt)
+10 worker.js implemented properly
+30 main.js implemented properly
Child Processes (src/cp)
+10 spawns child process
+10 child process stdin receives input from master process stdin
+10 child process stdout sends data to master process stdout

Comment thread src/cli/args.js
console.log(
argv
.filter((entity) => entity.match(/--\w*/))
.map((item) => `${item.slice(2)} is ${argv[argv.indexOf(item) + 1]}`)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this is correct implementation, I believe it is very inefficient due to indexOf call for each iteration of map.

Comment thread src/fs/copy.js
.catch(() => {
callback();
})
.then(async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When files folder does not exist, the promise still chains to then construction and creates empty files_copy folder. This is not right behaviour. Since it print FS operation failed twice, I will not deduct any point but the code has confusing semantics.

Comment thread src/fs/copy.js
.then(async () => {
await fsPromises
.access(pathTo)
.then(() => callback())

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then is for success flow

Comment thread src/fs/copy.js
await fsPromises
.access(pathTo)
.then(() => callback())
.catch(() => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not create folder when error occurs and you capture it in catch clause.

Comment thread src/fs/create.js
export const create = async () => {
await fsPromises
.access(pathToFile)
.catch(async () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you mistakenly swapped then with catch

Comment thread src/fs/delete.js
await remove(); No newline at end of file
function callback() {
try {
throw new Error("FS operation failed");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you throw Error inside try-catch block? When error occurs you would like to see stack trace and error object captures that information.

Comment thread src/fs/list.js

await list(); No newline at end of file
function callback() {
try {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment thread src/hash/calcHash.js
.then((fileBuffer) => {
console.log(createHash("sha256").update(fileBuffer).digest("hex"));
})
.catch((error) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the correct way of handling error.

Comment thread src/wt/main.js
)
})

console.log(await Promise.all(result));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to use here Promise.allSettled because Promise.allSettled() resolves when all the given promises have either fulfilled or rejected.
In your case, using Promise.all() resolves only when all given promises resolve, and will reject immediately if any of the promises reject (or non-promises throw an error).

Please read more here: https://www.designcise.com/web/tutorial/whats-the-difference-between-promise-all-and-promise-allsettled-in-javascript

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants