Skip to content
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

add timed delays for attribute resolution #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions utilities/assets-proxy-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,18 @@ class AssetsProxyPath {
let body = {
status: 'PENDING'
}
let milestonesDate = new Date().getTime();
let response = request('GET', `${this.nodeBaseUrl}/resolve?ids=${id}`);
const handler = JSON.parse(response.getBody()).handler_id
const handler = JSON.parse(response.getBody()).handler_id;
while (body.status === 'PENDING') {
new Date(new Date().getTime() + 1000);
response = request('GET', `${this.nodeBaseUrl}/resolve/result/${handler}`);
body = JSON.parse(response.getBody());
if((new Date().getTime()) > milestonesDate + 1000){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we use a sleep (setTimeout) here ? Otherwise the while loop will keep running and it might be cpu intensive

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, there is an issue with this Proxy class not having any async or await or promises in it. introducing the sleep using setTimeout will need the use of promises and will affect the usage of the sdk. I think this is the reason why we are using the sync-request library to make requests in the first place.

So my solution here seemed the best solution to delay requests, but i agree there is an infinite loop there.
we need to ask @kotlarmilos form more info about the proxy and whether we rewrite it to use promises instead.

new Date(new Date().getTime() + 1000);
response = request('GET', `${this.nodeBaseUrl}/resolve/result/${handler}`);
body = JSON.parse(response.getBody());
}
}
return body.data[0].result;
}
}

module.exports = AssetsProxyPath;
module.exports = AssetsProxyPath;