What is a proper way to wait Sugar Http response callback?

I lately discovered that the potential of Sugar library could be awesome.

I noticed that the test case of sugar http uses EUnit’s Waittoken,
However I am very curious about the possibility to utilize async or await syntax of Oxygene along Sugar Http on both android and ios platforms without Eunits.

var html: String; Http.ExecuteRequestAsString(new Url("http://www.remobjects.com"), resp -> begin html := resp.Content; end); //how to wait properly without EUnit's wait token? exit html;
I would like to make a async function that contains above source code.
Then i want to utilize this function in main thread like this.

label.text := async theFunction;

if this is possible, i could enjoy communicate http servers without asynctask class in android.

I hope this is possible but,
Please let me know if this is not a best practice even this is possible because the power of elements compilers.

Thank you.

I think you need to use a semaphore to make the code synchronous. You can then wrap a Task around that.

Also you could look at the eunit code to see what Waittoken is doing.

1 Like

thank you