Async/yield and mirrors

64 views
Skip to first unread message

Daniel Morilha

unread,
Feb 23, 2015, 12:17:49 PM2/23/15
to mi...@dartlang.org

Hi, is there a way through mirrors api to know if a function has any async/yield modifier. I didn't find anything on the api.  Thanks

Justin Fagnani

unread,
Feb 23, 2015, 12:28:06 PM2/23/15
to General Dart Discussion
It shouldn't matter. An async function and a sync function that returns a Future have no externally visible differences. What do you need?

On Mon, Feb 23, 2015 at 9:17 AM, Daniel Morilha <dmor...@gmail.com> wrote:

Hi, is there a way through mirrors api to know if a function has any async/yield modifier. I didn't find anything on the api.  Thanks

--
For other discussions, see https://groups.google.com/a/dartlang.org/
 
For HOWTO questions, visit http://stackoverflow.com/tags/dart
 
To file a bug report or feature request, go to http://www.dartbug.com/new

To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

Daniel Morilha

unread,
Feb 23, 2015, 12:36:51 PM2/23/15
to mi...@dartlang.org
I imagined I would hear something along those lines... I was just thinking how to treat them differently and remove the burden from the API user. I will figure out a different way.

Thanks Justin for the prompt answer.
--
Daniel Morilha (dmor...@gmail.com)

Justin Fagnani

unread,
Feb 23, 2015, 12:43:32 PM2/23/15
to General Dart Discussion
On Mon, Feb 23, 2015 at 9:36 AM, Daniel Morilha <dmor...@gmail.com> wrote:
I imagined I would hear something along those lines... I was just thinking how to treat them differently and remove the burden from the API user. I will figure out a different way.

Ok, I'm now curious in what way you would treat them differently and in what why there's a burden on the user? Can't you just check the return type for Future or Stream?

In what cases do you want to treat Future foo{} and Future foo async {} differently? They aren't actually different.

Daniel Morilha

unread,
Feb 23, 2015, 1:44:38 PM2/23/15
to mi...@dartlang.org
Hi,

checking the return type was something I didn't realize for whatever reason. Thanks Justin. The idea is to create a generic dispatcher and depending on the consumer, run it differently.

Sean Eagan

unread,
Feb 23, 2015, 2:45:53 PM2/23/15
to mi...@dartlang.org
Hi Daniel,

I wrote the `when` package for this use case:


It checks whether the return *value* is a Future, instead of the return *type*, which allows:

* avoids mirrors
* doesn't depend on the method author to annotate the return type as a Future (which is not required in dart).
* allows nested potentially-async callbacks

Hope it helps!

Cheers,
Sean
Reply all
Reply to author
Forward
0 new messages