Hi. I am creating an application in Node.js that has the following algorithm:The app asks for data to another application.The application will then reply to that request sending a POST request to an endpoint of my application after around 30 seconds.Once that data has arrived the flow of my application must take it and continue its normal execution.However I am facing the issue that I don't know how to schematize this data in a way that when the data arrives to the endpoint it can notify the other part of my app. In the optimal case I'd like to have a Promise that resolves once that data has arrived.So far, I've tried to do that but have had no luck, I've thought about two solutions. Do a setInteval that checks for the data every 5 seconds until it arrives or times out (at 5 minutes) or do a setTimeout that will check if the data arrived after the request has timed out.The problem with these approaches is pretty obvious, checking every 5 seconds is not efficient and also could delay the process ~5 seconds of what it would normally take in case the response arrives just after one check, so the app would be properly notified about it in the following check, that being 5 seconds after that. And in the case of the setTimeout it would make every request take the max amount of time, which is not convenient.I am almost sure there must be a way to achieve what I am trying to achieve with Promises, but I don't have enough experience using them to figure it out. I'd appreciate any pointing in the correct direction, and, in case I didn't express my problem clear enough let me know and I'll try to rephrase it.Thanks!
Submitted September 01, 2019 at 09:49PM by iwanttobemayor
No comments:
Post a Comment