is it possible to convert Task<List<>> to List<>?

Viewed 14444

I'm having problems with some of my code specifically this part. I'm calling an async method that returns a Task<List<>> (cant return a regular list because the method is async). But, I'm not able to convert it to a regular list, which is what I need. Is that even possible? If so, is anyone able to help out? :)

static void Main(string[] args) {
    Program p = new Program();

    List<Product> products = p.getProducts();
}

public async Task<List<Product>> getProducts() {
    // calling woocommerce api
    MyRestApi rest = new MyRestApi("http://someurl.com/wp-json/wc/v2", "consumer key", "consumer secret");
    WCObject wc = new WCObject(rest);

    List<Product> products = await wc.Product.GetAll();

    return await Task.Run(() => new List<Product>(products));
}
0 Answers
Related