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

Update functions to Async/Await #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kevingrozav
Copy link

Hi Sebastian,

Yay, my first pull request! I "promisified" the api helper functions and converted main function to use async/await.

fingers crossed.

Copy link
Member

@jsdelfino jsdelfino left a comment

Choose a reason for hiding this comment

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

Thanks for this pull request. Looks like a good start! I have a few review comments.

src/app.js Outdated
id
// Return a list of spaces the app belongs to
const spaces = (tok) => {
return new Promise((resolve, reject) => {
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest to convert this to use the async keyword (vs explicitly returning a Promise) and convert the asynchronous calls inside this function to use await (as this pull request seems to be about converting the sample async/await), instead of having a mix of async/await and promise programming models.

src/app.js Outdated
'https://api.watsonwork.ibm.com/v1/spaces/' + spaceId + '/messages', {
headers: {
Authorization: 'Bearer ' + tok
const token = (appId, secret) => {
Copy link
Member

Choose a reason for hiding this comment

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

Same comment as above, suggesting to convert to async/await as well.

src/app.js Outdated
};


// Send an app message to the conversation in a space
const send = (spaceId, text, tok) => {
Copy link
Member

Choose a reason for hiding this comment

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

Suggesting to convert to async/await here as well.

src/app.js Outdated
@@ -149,5 +139,4 @@ if(require.main === module)
(err) => {
if(err)
console.log('Error sending message:', err);
});

});
Copy link
Member

Choose a reason for hiding this comment

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

Not sure what that last character at the bottom of the file is.

  Description:
  Promisify post from request module,
  Convert callback style functions to implement async/await
  Remove done flag from unit test and check function
  Make unit test async/await
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

Successfully merging this pull request may close these issues.

2 participants