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

Improve Promise usage by using chaining #276

Open
markusthoemmes opened this issue Jul 16, 2018 · 2 comments
Open

Improve Promise usage by using chaining #276

markusthoemmes opened this issue Jul 16, 2018 · 2 comments

Comments

@markusthoemmes
Copy link
Contributor

Promises in the actions are plumbed together in a non-consistent way. Sometimes they use then/catch chaining, sometimes they are constructed globally and then resolve/reject is used. Sometimes, both ways are even mixed together.

We should review the code and fix all usages of Promises to use chaining. That's more readable in general and gives more guarantees on the Promise being actually resolved at some point.

@jberstler
Copy link

After doing a quick review, the only place I found where this can likely be tidied up is the main Promise in the web actions, for example: https://github.com/apache/incubator-openwhisk-package-kafka/blob/457f76dbd930a573fcfb427890a6c84645c8b61a/action/kafkaFeedWeb.js#L17

It seems that all paths within this function already return a Promise, and so the manually-constructed Promise is not needed.

However, all other instances of manually constructed Promises I found appear to be necessary as they are needed:

Of these, the only one I can think could be changed would be the last one, and that would require using nano in a way that natively returns Promises - not sure if that is possible, but it is worth investigating.

@markusthoemmes
Copy link
Contributor Author

@jberstler thanks for having a look!

To the first needed example: Couldn't every return path return an explicit Promise.resolved/Promise.reject instead of wrapping it? Dunno if that helps readability though.

The second is indeed how I expected to find things.

The third one could use https://nodejs.org/api/util.html#util_util_promisify_original (if that's available in the node version used).

The wrapping promise particularly nasty though, I think that should vanish as you pointed out.

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

No branches or pull requests

2 participants