Saturday, 14 September 2019

Async/Await, AWS S3 and Nodejs. Will event loop block?

Okay, so I know this question has been already asked and answered million times, but I need my code specific answers/suggestions to work around it.So I am building an app with Nodejs, Graphql, MongoDB and S3. basically, s3 should store created team's images, which are combination of user images.my code for users to join a team is this: https://pastebin.com/BWLre8jjmerge function: https://pastebin.com/tSic5aaathis merge function is being called on every resolver related to users and teams, for example, joinTeam, leaveTeam, etc..I am wondering this, there is small time window, even if it is milliseconds, when team image does not exist at all, and also from the behavior of await and event loop, if two users tried to join team, one of them might fail, or they might actually join, but team image might not get updated. will this be the case with my code? or, how could i solve this problem otherwise?I was thinking to add one field to a team in my database, set it to, for example "Busy" and check every resolver which has merge function in it and with that field, decide to let users send those particular requests. but this approach will be really bad if my application becomes big.I was thinking to do that merging on the front-end, but it would be slow compared to back-end approach.If someone could help me figure out how to work with this, I would be really glad.

Submitted September 14, 2019 at 04:12PM by warchild4l

No comments:

Post a Comment