asynchronousparametersvala

Return multiple values from async function


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?


Solution

  • 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);
    }