コード例 #1
0
ファイル: DictionaryTree.cs プロジェクト: lulzzz/BraneCloud
 /// <summary>
 /// This operation if inherently ambiguous in the context of nested properties.
 /// Therefore, to remain consistent, we define it at the top-level only.
 /// If the intent is to remove a KeyValuePair at ANY level, then
 /// the RemoveDeeply method is the one to use.
 /// </summary>
 /// <param name="item">The KeyValuePair to remove.</param>
 /// <returns>A boolean value indicating if the item was found and removed.</returns>
 public bool Remove(KeyValuePair <TKey, TValue> item)
 {
     lock (_syncRoot)
     {
         return(_localEntries.Remove(item));
     }
 }
コード例 #2
0
            private async Task ExecuteTokenAsync(Token token)
            {
                await Task.Yield();

                var task = token.GetTask();
                await task.ConfigureAwait(false);

                _tasks.Remove(token.Context);
            }
コード例 #3
0
            static void UncacheThread(ISynchronizedDictionary <Snowflake, CachedGuildChannel> channelCache, Dictionary <Snowflake, IReadOnlyList <CachedThreadChannel> > uncachedThreads, KeyValuePair <Snowflake, List <ChannelJsonModel> > kvp, CachedThreadChannel cachedThreadChannel)
            {
                channelCache.Remove(cachedThreadChannel.Id);
                List <CachedThreadChannel> list;

                if (uncachedThreads.TryGetValue(kvp.Key, out var boxedList))
                {
                    list = boxedList as List <CachedThreadChannel>;
                }
                else
                {
                    uncachedThreads.Add(kvp.Key, list = new List <CachedThreadChannel>());
                }
                list.Add(cachedThreadChannel);
            }
コード例 #4
0
        private async Task DelayReadyAsync(IGatewayApiClient shard, ReadyEventArgs e)
        {
            if (_delays.TryGetValue(shard.Id, out var delay))
            {
                // If a disconnection happened cancel the already existing delay.
                delay.Tcs.Cancel();
                shard.Logger.LogWarning("The ready delay was overwritten by a new session.");
            }

            var sw = Stopwatch.StartNew();

            using (delay = new DelayToken(shard.StoppingToken))
            {
                _delays[shard.Id] = delay;
                try
                {
                    await delay.Tcs.Task.ConfigureAwait(false);

                    // The task finished meaning all pending guilds were received.
                    // Now depending on the mode we either fire ready straight away or do chunking.
                    _delays.Remove(shard.Id);
                    switch (Dispatcher.ReadyEventDelayMode)
                    {
                    case ReadyEventDelayMode.Guilds:
                    {
                        shard.Logger.LogInformation("Ready. Received all pending guilds in {0}ms.", sw.ElapsedMilliseconds);
                        await InvokeEventAsync(e).ConfigureAwait(false);

                        break;
                    }

                        // TODO: some chunking design...?
                    }

                    if (InitialReadys.TryGetValue(shard.Id, out var readyTcs))
                    {
                        readyTcs.Complete();
                    }
                }
                catch (OperationCanceledException)
                { }
            }
        }