Skip to content

Instantly share code, notes, and snippets.

@MagnusThor
Created February 4, 2016 17:04
Show Gist options
  • Save MagnusThor/8b30c14567158f0b74bd to your computer and use it in GitHub Desktop.
Save MagnusThor/8b30c14567158f0b74bd to your computer and use it in GitHub Desktop.
Task Async Helper Stub
private IEnumerable<FakeOrder> CallServiceToFind(string query)
{
System.Threading.Thread.Sleep(1000);
return orders.Where(p => p.ProjectName.ToLower().Contains(query.ToLower())).Take(400);
}
private Task<IEnumerable<FakeOrder>> _task { get; set; }
public async Task FindOrder(string query,int chunks = 10,int wait = 1000)
{
try
{
_task?.Forget();
_task =
TaskAsyncHelper.FromResult(CallServiceToFind(query));
await _task.ContinueWith(async task => {
await this.ChunkInvoke(task.Result, "results", 10, 250).ContinueWith(async completed => {
await this.Invoke(new {status = completed.Status, p = completed.Id}, "findorderstatus");
});
});
}
catch (Exception ex)
{
await this.InvokeError(ex, "FindOrder");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment