I think your method slightly violates the principle of single responsibility , because it does too much.
First of all, I suggest changing CreateItems to return Task instead of wrapping it in GetItemsAsync :
public Task<Item[]> CreateItems(CancellationToken token) { return Task.Factory.StartNew(() =>
CancellationToken is optional, but can help you if you can cancel this lengthy operation.
With this method, you can completely remove GetItemsAsync because it is so easy to process the results with your client without passing this delegate:
Using this approach, you will get a clearer code with one responsibility. The Task class itself is an ideal tool for representing an asynchronous operation as the first object of a class . Using the proposed technique, you can easily make fun of your current implementation with fake behavior for unit testing without changing the code of your clients.
Sergey Teplyakov
source share