haxetink / tink_await

Haxe async/await
MIT License
58 stars 15 forks source link

Allow transforming local function without putting restriction on the wrapping function #16

Open kevinresol opened 7 years ago

kevinresol commented 7 years ago

I would like to do this:

@:await
class Await {
  public function wrapper() {
    @:async function local() {
      // ...
    }
  }
}

Note that wrapper is not tagged by @:await nor @:async

benmerckx commented 7 years ago

That means we'd have to check all expressions of every method to see if it contains the metadata. But if this is something you regularly need, we could enable it behind a flag and see how it goes?

kevinresol commented 7 years ago

Or introducing another meta besides await and async which is used to only indicate there are something to get transformed inside?

benmerckx commented 7 years ago

That's what @:await on a method is already there for?

@:await
class Await {
    @:await function wrapper() {
        @:async function local() {
            return @:await something();
        }
        // ... use local ...
    }
}
kevinresol commented 7 years ago

Oh I thought @:await forces the function to return Void. If that's not the case, this can be closed.

benmerckx commented 7 years ago

It doesn't :) It works as you proposed:

to only indicate there are something to get transformed inside

I've added a test here, but let's keep this open so I can add some info in the docs. I didn't before because I wasn't sure about the name (as @:await now has a different meaning on either class/method/expr). But after this time I don't think I'm going to come up with something better :)

benmerckx commented 7 years ago

Oh, wait I spoke too soon. A method marked @:await does force its return type to Void, but only once an @:await expression is used. I need a minute to check that restriction..

benmerckx commented 7 years ago

So, this works:

@:await function wrapper() {
    @:async function local() {
        return @:await something();
    }
    return whatever;
}

But, this doesn't:

@:await function wrapper() {
    @:await something();
    return whatever;
}

Because it cannot get transformed to something that makes sense.

kevinresol commented 7 years ago

Ok, then great. And the Void case is very understandable. Thanks.