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

ApiMethod with async #29

Closed
mmaquevice opened this issue Mar 27, 2015 · 8 comments
Closed

ApiMethod with async #29

mmaquevice opened this issue Mar 27, 2015 · 8 comments

Comments

@mmaquevice
Copy link

Congrats for RPC ! :)

Are you planning to support async api method ?

e.g. :

@ApiMethod(path: 'myPath')
MyResponse get(String id) async {
...
}
@cgarciae
Copy link

@mmaquevice your MyRespose type is really a Future<SomeClass> since you are creating an async function. RPC already support returning futures and since in Dart you can't distinguish a sync function that returns a Future<A>, from an async function that "returns" an A, then you already have this functionality.

@mmaquevice
Copy link
Author

My bad, I thought it didn't work but you're right!

@jkriesel
Copy link

The problem with this is that you can't use the await keyword. I have an api method that does a request to a separate back-end server (i.e. elastic search) and would like to wait for the response before returning. Is there a work around for this?

@Kleak
Copy link
Contributor

Kleak commented Jun 28, 2016

you can use await just add async on the function declaration

class TestResponse {
  int result;
}

@ApiMethod(name: 'test upload', path: 'test', method: 'GET')
Future<TestResponse> test() async {
  int number = await new Future.value(12);
  return new TestResponse()..result = number;
}

@jkriesel
Copy link

How does this work from the client? You can't really have a Future of a Future.. can you?

@Kleak
Copy link
Contributor

Kleak commented Jun 28, 2016

on the client side there is no difference.

@jkriesel
Copy link

jkriesel commented Jun 28, 2016

Within the client api, the client api returns a future already. You'd end up with Future of a Future

@Kleak
Copy link
Contributor

Kleak commented Jun 29, 2016

No just a future

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

4 participants