question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why does CreateAsync return Task<IEnumerable<TItem>>?

See original GitHub issue

https://github.com/IEvangelist/azure-cosmos-dotnet-repository/blob/main/Microsoft.Azure.CosmosRepository/src/IRepository.cs#L78

return Task<IEnumerable<TItem>> while

https://github.com/IEvangelist/azure-cosmos-dotnet-repository/blob/main/Microsoft.Azure.CosmosRepository/src/IRepository.cs#L64

returns ValueTask<IEnumerable<TItem>> any reasons why they are not alike?

Also, notice the xml doc is not up to date. Happy to send a PR if wanted. It seems though changing the interface return type is a breaking change so I wanted to ask first

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
danielmarbachcommented, Oct 9, 2020

😍🤩Glad my rambling was helpful

1reaction
danielmarbachcommented, Oct 9, 2020

I understand that reasons why when doing concurrent processing with WhenAll you need to return Task. I was more wondering from the interface perspective. Because aren’t you technically now leaking implementation details to the interface definition?

It seems that the return type is basically bound to the implementation that happens to fan out CreateAsync but from an interface definition perspective, you could also argue that an implementor of the interface could implement this interface internally by using a transactional batch and then there would be mostly synchronous calls to the batch and one ExecuteAsync call which then would allow to essentially return ValueTask again and thus benefit from the value task pooling.

I think my feedback is that it is suprising that the concurrency implementation detail suddendly leaks into the interface definition. From the perspective of the implementation you could also return a ValueTask and then still internally do a when all and be compliant with the Value Task returning API like the following

        public async ValueTask<IEnumerable<TItem>> CreateAsync(IEnumerable<TItem> values)
        {
            IEnumerable<Task<TItem>> concurrentCreationTasks = values.Select(v => CreateAsync(v).AsTask()).ToList();
            await Task.WhenAll(concurrentCreationTasks);
            return concurrentCreationTasks.Select(x => x.Result);
        }

then you allow implementors of the interface to decide how the handle the creation of the multiple items and you are no longer “leaking” the implemenation of the DefaultRepository into the interface definition.

Read more comments on GitHub >

github_iconTop Results From Across the Web

UserManager.CreateAsync .Success always returns false
UserManager.CreateAsync returns an IdentityResult that would also contain any errors why the action was not successful.
Read more >
UserManager<TUser>.CreateAsync Method
Creates the specified user in the backing store with no password, as an asynchronous operation.
Read more >
override createAsync in IdentityUserAppService not executed ...
Im trying custom create user by admin in abp,so override createAsync in IdentityUserAppService,but this part of code not executed
Read more >
Issues in Optimizely when creating large number of users ...
Hi, We are trying to create around 100k users in Optimizely programmatically but the issue is can't able to run _userManager.CreateAsync ...
Read more >
ASP.NET Core - Create a User
This Async method returns a result that tells us if the instance was a success or a failure and if it failed, it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found