No returned task for await in closure callbacks

Hi,
I was looking at the blog post https://blogs.remobjects.com/2019/06/28/introducing-await-for-closure-callbacks/

The given example is

method DownloadData;
begin
  var lResponse := await Http.ExecuteRequestAsJson(new HttpRequest(URL));
  if lassigned(aResponse.Content) then begin
    await dispatch_async(dispatch_get_main_queue());
    fData := lResponse.Content;
    tableView.reloadData;
  end;
end;

When I’m using await in .net the method DownloadData would return a Task. Why doesn’t the code in this example do the same ?

Thanks,
John

Mainly because task is a .NET specific API, while this sample uses Elements RTL, which is cross-platform and not using then general async/await infrastructure of .NET. The whole point fo awaitable closures is to be able to see await with APIs that don’t already support Task.

Oh. Would it be possible to add that kind of support in a cross platform manner ?

I have some code in an iOS app that makes multiple http requests and then waits for all to finish before doing something else. Currently I’m using NSOperationQueue but I think I would prefer to use Tasks.

Actually why do you call Task a .Net specific API when you have cross platform support for it ?

This IS cross platform. :slight_smile:

Because I used await in .net first, I would expect it to return a Task, so when I look at the code I cant tell what its going to do

For example if I have a button hooked up to some method

[IBAction]method doIt(sender:id);
begin
DownloadData;
SomeOtherMethod;
end;

Is it going to reloadData before or after SomeOtherMethod is called ?

If a Task was returned, I know I need to do a Wait to make SomeOtherMethod be after.

Well, this is a different paradigm, and especially designed for methods that take a callback. The point ti that fete (say on Cocoa oa Java) these APIs aren’t really ours to redesign toms Task (if we wanted to). This feature lets you use await on the even though they don’t use Task — that’s the whole point — and they’ll use the callback to execute the remaining code. Think if it as the remainder of the method body/scope being moved into the closure.