-
Notifications
You must be signed in to change notification settings - Fork 29.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: update stream.reduce
concurrency note
#47166
Merged
nodejs-github-bot
merged 1 commit into
nodejs:main
from
rluvaton:update-stream-operator-reduce-docs
Mar 24, 2023
Merged
doc: update stream.reduce
concurrency note
#47166
nodejs-github-bot
merged 1 commit into
nodejs:main
from
rluvaton:update-stream-operator-reduce-docs
Mar 24, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nodejs-github-bot
added
doc
Issues and PRs related to the documentations.
stream
Issues and PRs related to the stream subsystem.
labels
Mar 19, 2023
rluvaton
force-pushed
the
update-stream-operator-reduce-docs
branch
from
March 19, 2023 21:18
2a31082
to
4b92bfd
Compare
rluvaton
force-pushed
the
update-stream-operator-reduce-docs
branch
2 times, most recently
from
March 19, 2023 22:58
2ac4139
to
487f5db
Compare
rluvaton
force-pushed
the
update-stream-operator-reduce-docs
branch
from
March 20, 2023 00:17
487f5db
to
9627c88
Compare
rluvaton
commented
Mar 20, 2023
Comment on lines
2508
to
+2523
```mjs | ||
import { Readable } from 'node:stream'; | ||
import { readdir, stat } from 'node:fs/promises'; | ||
import { join } from 'node:path'; | ||
|
||
const ten = await Readable.from([1, 2, 3, 4]).reduce((previous, data) => { | ||
return previous + data; | ||
}); | ||
console.log(ten); // 10 | ||
const directoryPath = './src'; | ||
const filesInDir = await readdir(directoryPath); | ||
|
||
const folderSize = await Readable.from(filesInDir) | ||
.reduce(async (totalSize, file) => { | ||
const { size } = await stat(join(directoryPath, file)); | ||
return totalSize + size; | ||
}, 0); | ||
|
||
console.log(folderSize); | ||
``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated this example as well so the refactor can be more obvious
mcollina
approved these changes
Mar 21, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
github-actions
bot
removed
the
request-ci
Add this label to start a Jenkins CI on a PR.
label
Mar 21, 2023
Hey @VoltrexKeyva , can you please rereview so it can be merged? |
VoltrexKeyva
approved these changes
Mar 23, 2023
Thanks @VoltrexKeyva , can you merge it? |
VoltrexKeyva
added
the
commit-queue
Add this label to land a pull request using GitHub Actions.
label
Mar 24, 2023
nodejs-github-bot
removed
the
commit-queue
Add this label to land a pull request using GitHub Actions.
label
Mar 24, 2023
Landed in c588145 |
RafaelGSS
pushed a commit
that referenced
this pull request
Apr 5, 2023
PR-URL: #47166 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Merged
RafaelGSS
pushed a commit
that referenced
this pull request
Apr 6, 2023
PR-URL: #47166 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
RafaelGSS
pushed a commit
that referenced
this pull request
Apr 7, 2023
PR-URL: #47166 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
danielleadams
pushed a commit
that referenced
this pull request
Jul 6, 2023
PR-URL: #47166 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
At first, when I read that note I thought I should do this:
This did not work and does not make any sense as the map items are emitted in the order that got from the readable stream.
So I thought of changing to note to recommend implementing reduce using
.forEach
with concurrency but then I understand what @benjamingr meant when he wrote that note - because the only way you will need concurrency is if you do some async operation (because sync block the loop - bla bla) and that operation can be parallelized so I updated the note with an example@benjamingr, hope this is what you meant 😅