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 async await syntax. #57

Closed
wants to merge 2 commits into from
Closed

Add async await syntax. #57

wants to merge 2 commits into from

Conversation

Exitare
Copy link
Contributor

@Exitare Exitare commented Apr 24, 2020

Add the possibility to use async/await as discussed in #56
E.g.

`
const Hook: webhook.Webhook = new webhook.Webhook("WEBHOOK URL");

const msg = new webhook.MessageBuilder().setAuthor("TEST_AUTHOR");

await Hook.send(msg);
`

Copy link
Owner

@jb3 jb3 left a comment

Choose a reason for hiding this comment

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

I might be missing some stuff but I'm not fully seeing the benefits here

@@ -302,12 +302,12 @@ class Webhook {
if (
messageBuilder.data.text // Check for any text
) {
return this.sendPayload(messageBuilder.data, resolve);
return await this.sendPayload(messageBuilder.data, resolve);
Copy link
Owner

Choose a reason for hiding this comment

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

Do we still need a resolve function? This was messy when I wrote it and still is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then this should be resolved in future commits. Not in this pr.

Copy link
Owner

Choose a reason for hiding this comment

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

No, this resolve function was introduced with the old async system, it's just unused now.

If we introduce async/await syntax then we go all the way, we don't mess around with old style promises and new style.

@jb3 jb3 self-requested a review May 6, 2020 09:17
@jb3
Copy link
Owner

jb3 commented May 6, 2020

Accidentally marked as approved

Copy link
Owner

@jb3 jb3 left a comment

Choose a reason for hiding this comment

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

See comments above

@jb3
Copy link
Owner

jb3 commented May 6, 2020

Also looks like there is a gnarly eslint error in there

@Exitare
Copy link
Contributor Author

Exitare commented May 7, 2020

The benefit is to use async and await syntax. As discussed. This pr is just to introduce them and make it available. It does not fix bad coding decisions nor any logical errors. This should be handled by other pull requests.

@jb3
Copy link
Owner

jb3 commented May 7, 2020

@Exitare the implementation you have proposed is broken. It does not work at all, I appreciate another PR should fix "poor coding decisions" but this is not working by any means.

/Users/joseph/Desktop/Projects/JavaScript/Node.js/webhook-discord/lib/webhook.js:109
                                    await this.sendPayload(payload, resolve);
                                    ^^^^^

SyntaxError: await is only valid in async function
    at new Script (vm.js:79:7)
    at createScript (vm.js:251:10)
    at Object.runInThisContext (vm.js:303:10)
    at Module._compile (internal/modules/cjs/loader.js:657:28)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)

@Exitare
Copy link
Contributor Author

Exitare commented May 7, 2020

That wasn’t meant to be rude. Anyways, I don’t have any time to spare in the foreseeable future and therefore will close this PR. If someone would like to take over feel free to do that.

@Exitare Exitare closed this May 7, 2020
@jb3
Copy link
Owner

jb3 commented May 7, 2020

I'll look into it. I do agree though that the current async system is iffy, if it is reimplemented it should be a full rewrite of all the promises.

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

Successfully merging this pull request may close these issues.

2 participants