async Task <AssetEntry <ISyncModel> > DownloadSyncModel(StreamKey streamKey, string hash, CancellationToken token) { StreamCache cache; lock (m_StreamCaches) { if (!m_StreamCaches.TryGetValue(streamKey, out cache)) { m_StreamCaches[streamKey] = cache = new StreamCache(streamKey); } } Task <ISyncModel> task; var isTaskOwner = false; lock (cache) { if (cache.model != null && cache.hash == hash) { return(new AssetEntry <ISyncModel>(streamKey, cache.model)); } if (cache.task != null) { task = cache.task; } else { isTaskOwner = true; cache.model = null; cache.hash = hash; cache.task = task = m_Client.GetSyncModelAsync(cache.streamKey, cache.hash); // TODO Cancellation Token } } token.ThrowIfCancellationRequested(); var syncModel = await task; if (isTaskOwner) { lock (cache) { cache.model = syncModel; cache.task = null; } } return(new AssetEntry <ISyncModel>(streamKey, syncModel)); }
async Task DownloadInstance(StreamAsset request, CancellationToken token) { DownloadResult result; try { var instance = (SyncObjectInstance)await m_Client.GetSyncModelAsync(request.key, request.hash); // TODO Cancellation Token result = new DownloadResult(request, instance, null); } catch (Exception ex) { result = new DownloadResult(request, null, ex); } m_DownloadResults.Enqueue(result); }