1

I'm having trouble to write an "async" function that returns more than one value using "out".

public async void getArticle(int articleID, out string html, out string title, out string author, out string url)
{

}

this is enough to trigger the error. As soon as the keyword "async" ist part of the function header I get the following error when calling the function:

error: Argument 2: Cannot convert from `string?' to `GLib.AsyncReadyCallback?'

this is what the call looks like

getArticle(15752, out html, out title, out author, out url);

if I remove the keyword "async" everything starts working again. Is this even possible in vala or do I have to return an object containing all 4 strings to make it work?

Thanks for any help in advance

best regards, Jan

1 Answers1

3

You have to use the out parameters on the end of the asynchronous method:

getArticle.begin(15752, (obj, result) => {
  getArticle.end(result, out html, out title, out author, out url);
}
apmasell
  • 7,033
  • 19
  • 28
  • thx, but how do I get the values out of this lambda expression? Something like "getArticle.begin(15752, (obj, result, html, title, author, url) => { getArticle.end(result, out html, out title, out author, out url); });" does not work – Jan Lukas Gernert Sep 03 '14 at 02:33
  • 1
    The callback is invoked after the function finishes executing, but the next line after the begin() call is invoked immediately. There is no way to access the out variables because the values don't necessarily exist yet. Take a look at https://wiki.gnome.org/Projects/Vala/Tutorial#Asynchronous_Methods for more information. – nemequ Sep 03 '14 at 08:08