-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
fix: Remove awaits in loop #3979
Conversation
Codecov Report
@@ Coverage Diff @@
## development #3979 +/- ##
===============================================
+ Coverage 21.93% 21.93% +<.01%
===============================================
Files 460 460
Lines 4733 4728 -5
===============================================
- Hits 1038 1037 -1
+ Misses 3695 3691 -4
Continue to review full report at Codecov.
|
app/mixins/event-wizard.js
Outdated
} | ||
})); | ||
propsToSave.map((property, index) => { | ||
promises.then(promise => { data[property] = promise[index] }); |
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.
These are already resolved promises. No need to then these promises
app/mixins/event-wizard.js
Outdated
} catch (e) { | ||
if (!(e.errors && e.errors.length && e.errors.length > 0 && e.errors[0].status === 404)) { | ||
// Lets just ignore any 404s that might occur. And throw the rest for the caller fn to catch | ||
throw e; | ||
} | ||
} | ||
} | ||
})); | ||
propsToSave.map((property, index) => { |
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.
Use for of loop
Sorry for the inconvenience, I'm having problems while using rebase. I'm learning. I'll not make these mistakes in the future. |
4309f76
to
61a9791
Compare
@iamareebjamal I did everything right this time besides the force push. Then why it is showing that the codecov/patch was not successful? |
app/mixins/event-wizard.js
Outdated
} catch (e) { | ||
if (!(e.errors && e.errors.length && e.errors.length > 0 && e.errors[0].status === 404)) { | ||
// Lets just ignore any 404s that might occur. And throw the rest for the caller fn to catch | ||
throw e; | ||
} | ||
} | ||
})); | ||
for (const [index, property] of propsToSave.entries()) { | ||
data[property] = promises[index]; |
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.
You need to assign only if it was successful
app/mixins/event-wizard.js
Outdated
@@ -48,28 +48,31 @@ export default Mixin.create(MutableArray, CustomFormMixin, { | |||
async saveEventData(propsToSave = []) { | |||
const event = this.get('model.event'); | |||
const data = {}; | |||
for (const property of propsToSave) { | |||
const promises = await Promise.all(propsToSave.map(property => { |
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.
Use Promise.allSettled
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.
The last commit didn't pass. I replaced Promise.all with Promise.allSettled. What else should I do?
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.
See what allSettled returns
88967ab
to
ca917d6
Compare
app/mixins/event-wizard.js
Outdated
} | ||
})); | ||
results.then(promises => { | ||
for (const [index, property] of propsToSave.entries()) { |
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.
No need to extract index
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.
Then how can I assign the value of event.get(property)
without using the index
?
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.
By using property
fee07d5
to
8b0ca3a
Compare
Issues
======
+ Solved 10
See the complete overview on Codacy |
Fixes #3916
Short description of what this resolves:
If we're performing an operation on each element of an iterable and
await
is a part of each operation then the program is not taking full advantage of parallelization benefits ofasync
/await
. Each successive operation will not start until the previous one has completed.Using
Promise.all()
toawait
all the requests that were kicked during the loop to finish will create all the promises at once.This pull request fixes this issue.
Checklist
development
branch.