You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
for loop, inside async setter doesn't wait all Promise. #3898
How often does it reproduce? Is there a required condition?
Everytime.
What is the expected behavior?
{ q: 'q', w: 'w', e: 'e', r: 'r', a: 'a' }
What do you see instead?
{ q: 'q', w: 'w', e: 'e' }
Additional information
As I wrote, I can loop with Object.keys.
but I've spent several hours to find this problem.
If I'm not wrong with that code - using for..in loop inside async setter - hope it fixed.
The promise your setter returns in ignored by the engine, it will treat it as a truthy boolean value and that's all. So when you write await (_instance.attributes = attrs);, _instance.attributes = attrs will evaluate to the value of attrs, not the Promise your setter returns.
If you add a setTimeout(() => console.log(foo.attributes), 300);, you'll see that all the properties are there eventually.
Trying to set property asynchronously is dangerous, you can get into race conditions very easily if more than one async branch tries to write data concurrently, I wouldn't recommend it.
If async setters is really what you want, here are some (not so good) examples
You'd either need to expose some property that returns a promise that resolves when the instance is ready:
Activity
aduh95 commentedon Jun 19, 2022
The promise your setter returns in ignored by the engine, it will treat it as a truthy boolean value and that's all. So when you write
await (_instance.attributes = attrs);,_instance.attributes = attrswill evaluate to the value ofattrs, not the Promise your setter returns.If you add a
setTimeout(() => console.log(foo.attributes), 300);, you'll see that all the properties are there eventually.Trying to set property asynchronously is dangerous, you can get into race conditions very easily if more than one async branch tries to write data concurrently, I wouldn't recommend it.
If async setters is really what you want, here are some (not so good) examples
You'd either need to expose some property that returns a promise that resolves when the instance is ready:
Or make an async method:
duecorda commentedon Jun 19, 2022
Thank you for your kind answer.
May I need change my structure.