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

Using promises in API operations #3058

Closed
uxkjaer opened this issue Oct 27, 2020 · 4 comments
Closed

Using promises in API operations #3058

uxkjaer opened this issue Oct 27, 2020 · 4 comments

Comments

@uxkjaer
Copy link
Member

uxkjaer commented Oct 27, 2020

OpenUI5 version: *

Browser/version (+device/version): All except IE

Any other tested browsers/devices(OK/FAIL):

I recently checked https://www.w3schools.com/browsers/browsers_explorer.asp for IE stats and it's sitting at 0.6 overall usage. I was hoping it might be time to consider using promises in the odata model instead of callback functions.
Pascal Wasem wrote a good blog on how to user a wrapper to promisify it, I've had a look at the source code and manage to use promises for read, remove, update, create, submitchanges and call function, just by adding and returning the promise.

Check out commit uxkjaer@49777ed.
Currently it's been hacked and slashed a bit, but I'd be happy to tidy it up, if you think there is a future in this.

@tsanislavgatev
Copy link
Contributor

I've created an internal incident 2070435570. The status of the issue will be updated here in GitHub.

@pubmikeb
Copy link

Yeah, in 2021 it's a time to use async/await instead of callbacks.

@uxkjaer
Copy link
Member Author

uxkjaer commented Oct 27, 2020

Yeah, with the proposed changes, I had this working without any additional efforts
image

And also checked for backwards compatability, no issues (Except for IE support)
image

@larskissel
Copy link
Member

Hi @uxkjaer

thanks for this suggestion and your contribution.

I understand your point, but unfortunately, I must tell you that this idea wouldn’t be compatible to the behavior of the V2 ODataModel. A returned promise would change the function usage, which is also incompatible. For example, the ODataModel#read method specifies the return value as “an object which has an abort function to abort the current request”. If we would return a promise, this functionality wouldn’t work anymore as specified in the API.

This is why it is currently not planned to adopt such a functionality within the V2 ODataModel.

Best regards,
Lars

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants