lundi 24 juin 2019

Using Task<> in a library

I'm designing the software architecture for a product who can instantiate a series of "agents" doing some useful things. Let's say each agent implement an interface having a function:

Task AsyncRun(CancellationToken token)

Because since these agents are doing a lot of I/O it could make some sense having as an async function. More over, the AsyncRun is supposed never complete, if no exception or explict cancellation occour.

Now the question is: main program has to run this on multiple agents, I would like to know the correct way of running that multiple task, signal each single completion ( that are due to cancellation/errors ) and I would like to know if this is the correct pattern, especially because the implementer can mismatch the RunAsync and do a blocking call, in which case the entire application will hang.

Aucun commentaire:

Enregistrer un commentaire