Created
February 4, 2016 17:04
-
-
Save MagnusThor/8b30c14567158f0b74bd to your computer and use it in GitHub Desktop.
Task Async Helper Stub
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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