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

[question] async call in constructor #4632

Closed
Inve1951 opened this issue Aug 5, 2017 · 5 comments
Closed

[question] async call in constructor #4632

Inve1951 opened this issue Aug 5, 2017 · 5 comments
Labels

Comments

@Inve1951
Copy link
Contributor

Inve1951 commented Aug 5, 2017

this is my first time trying to use await/promises

in a class constructor i put this:

if await new Promise (r) =>
  cache.get @url, (b) =>
    r b
    return
  return
then return

since that gave me error: Class constructor may not be async when compiling i tried to work around it by wrapping it with do =>:

do =>
  if await new Promise (r) =>
    cache.get @url, (b) =>
      r b
      return
    return
  then return

which throws at runtime with Uncaught SyntaxError: Unexpected token ( after async
i get the same result when adding a space after async

so my question is, what am i doing wrong?

@Inve1951
Copy link
Contributor Author

Inve1951 commented Aug 5, 2017

just realized the electron environment i'm forced to deal with is based on chrome 53 and node 6.5 which didn't have asynch/await yet

@Inve1951 Inve1951 closed this as completed Aug 5, 2017
@GeoffreyBooth
Copy link
Collaborator

@Inve1951
Copy link
Contributor Author

Inve1951 commented Aug 7, 2017

see what the second snippet compiles to
if that's bad js should the compiler catch that too?
@GeoffreyBooth

@GeoffreyBooth
Copy link
Collaborator

Second snippet runs for me in Chrome, as long as cache is defined.

@Inve1951
Copy link
Contributor Author

Inve1951 commented Aug 7, 2017

then i was right with the environment just being outdated, thanks

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

No branches or pull requests

2 participants