Custom async DataListSource for Contentment
# help-with-umbraco
j
I am wondering if anyone else has tried creating a custom DataListSource for Contentment where you need to get the items async from another service? Doesn't look like GetItems has an async version, so wondering if this is possible. What I'd like to do is something like this:
Copy code
csharp
public async Task<List<DataListItem>> GetItems(Dictionary<string, object> config)
{
    var items = new List<DataListItem>();

    var categories = await _productService.GetCategories();

    foreach (var category in categories)
    {
        items.Add(new DataListItem
        {
            Name = category.Name,
            Value = category.EntityId.ToString()
        });
    }

    return items;
}
Hmm just found this so it's looking unlikely 🙂 Will leave the post up in case someone has found a nice workaround! https://github.com/leekelleher/umbraco-contentment/discussions/259
s
Is it because you can't return a Task?
var categories = await _productService.GetCategories().Result;
will make it a regular sync call so you could pretend it was never async to begin with? 😅
j
Oh yea, good point - hadn't considdered that 😄