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

Way to mark a method as "async" #214

Closed
marcoscaceres opened this issue Oct 31, 2016 · 2 comments
Closed

Way to mark a method as "async" #214

marcoscaceres opened this issue Oct 31, 2016 · 2 comments

Comments

@marcoscaceres
Copy link
Member

It would be nice if WebIDL provided a means to mark a method as async, like:

interface Foo {
   async returnValue whatever(); 
}

I was reading the Web Payments spec and noticed that they are using exceptions and promises incorrectly (they try to throw exceptions before they return the promise). Something like the above would prevent such issues by implicitly returning the promise. Any thrown exceptions in the method's prose will then just be converted to rejections by the promise machinery.

Furthermore, such methods could then use "await" semantics if they need to wait for other methods or even internal "promises", etc.

So, like:

When foo() is called:

  1. If some condition, throw a WhatEvesError.
  2. If [[slot]] was not set, throw NotAllowedError.
  3. Let x be there result of awaiting thing that happens in another thread (where "thing" runs in parallel).
  4. return x.

And 4. nicely resolves the promise. Or some such.

@domenic
Copy link
Member

domenic commented Oct 31, 2016

This is already provided by Web IDL. Returning a promise type implicitly transforms any throws to rejections and returns to fulfillments: https://heycam.github.io/webidl/#dfn-create-operation-function step 2. So instead of async returnValue just do Promise<returnValue>. I think it's bad practice to be implicit in this way though.

I think the awaiting construct you describe is not good. It's mixing up two things: in parallel, and promises. You shouldn't be able to await non-promises. If you want to await promises, use https://heycam.github.io/webidl/#dfn-perform-steps-once-promise-is-settled; if you want to wait until things run in parallel, just "Wait, in parallel".

@marcoscaceres
Copy link
Member Author

@domenic, thanks for the clarification.

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

No branches or pull requests

2 participants