Await is not supported here

Go to (or Peek at) Definition, see my two screenshots. value2 is not a Task.

Thats bit a closure though, its a method explicitly defined to return a Task<Model>, so that matches what is expected as parameter, and it compiles. The compiler knows it needs to return a Task, and does the right thing.

The way the anonymous methods work, as I understand it, that it doesn’t look at the surrounding scope (ie the call to the TransformBlock .ctor) to see what it might like to receive as a parameter (especially, as there ar many overload, that’d be difficult. it looks at the cod win the anonymous method, and from that infers its signature (which is not a Task<Model> result, but a Model). And that then does mot match any of the actor overloads.

if that makes sense.

Thanks. That makes sense

Logged as bugs://E26841.

bugs://E26841 was closed as fixed.

What was fixed ?

I was wrong. the closure DID have an explicit return type, so inference of that was not the issue.

Thanks.

Should this also work ?

      var t5 := new TransformBlock<Model, Model>(value1 ->
      begin
        var value2 := await DoIt;
        exit value1;
      end,
      new ExecutionDataflowBlockOptions(MaxDegreeOfParallelism := 5)
      );

Ive returned the incoming parameter rather than the value from the await.

I don’t know, I cant really tell from lookin at random snippets, as I’m not the compiler ;).

It seems this one SHOULD fail, as its the case I describe, where the anon does not have an explicit return type, so it result would be inferred as plain non-task Model. but I really can’t say for sure.

Yes that would be it.

  Program = class
  public

    class method DoIt : Task<Model>;
    begin
      exit Task.FromResult(new Model);
    end;

    class method Main(args: array of String): Task<Int32>;
    begin

      await DoIt;

      var t1 := new TransformBlock<Model, Model>(value1 ->
      begin
        var value2 := await DoIt;
        exit value1;
      end,
      new ExecutionDataflowBlockOptions(MaxDegreeOfParallelism := 5)
      );


    end;

I sort of figured that the compiler would see the await in the anon method and automatically change the result of anything to Task so i could return value1 or value2.

So If I want to call await without returning a value or the above I should do this and not use anon methods

  Program = class
  public

    class method DoIt(value:Model) : Task<Model>;
    begin
      await Task.Delay(TimeSpan.FromSeconds(10));
      exit new Model;
    end;

    class method Main(args: array of String): Task<Int32>;
    begin

      var t1 := new TransformBlock<Model, Model>(value1 -> DoIt(value1),
      new ExecutionDataflowBlockOptions(MaxDegreeOfParallelism := 5)
      );


    end;

Or at least specify the proper signature for the anon – which I believe is what @ck fixed?