public async Task <Possible <string, Failure>[]> PinToCasAsync(CasEntries casEntries, UrgencyHint urgencyHint, Guid activityId) { Contract.Requires(!IsClosed); Contract.Requires(casEntries.IsValid); using (var eventing = new PinToCasMultipleActivity(BasicFilesystemCache.EventSource, activityId, this)) { eventing.Start(casEntries, urgencyHint); // First, initiate all of the operations var taskValues = new Task <Possible <string, Failure> > [casEntries.Count]; for (int i = 0; i < casEntries.Count; i++) { taskValues[i] = PinToCasAsync(casEntries[i], urgencyHint, activityId); } // Now await them all (since they can run in parallel var results = new Possible <string, Failure> [casEntries.Count]; for (int i = 0; i < casEntries.Count; i++) { results[i] = await taskValues[i]; } // All return results are actually traced via the per-hash call of PinToCas return(eventing.Returns(results)); } }
public async Task <Possible <string, Failure>[]> PinToCasAsync(CasEntries hashes, UrgencyHint urgencyHint, Guid activityId) { using (var eventing = new PinToCasMultipleActivity(CompositingCache.EventSource, activityId, this)) { eventing.Start(hashes, urgencyHint); var results = await m_casSession.PinToCasAsync(hashes, urgencyHint, eventing.Id); for (int i = 0; i < results.Length; i++) { if (results[i].Succeeded) { PinnedToCas.TryAdd(hashes[i], 0); } } return(eventing.Returns(results)); } }