예제 #1
0
        public Task <int> GetAsync(long key)
        {
            if (!this.lockDict.ContainsKey(key))
            {
                this.locations.TryGetValue(key, out int location);
                Log.Info($"location get key: {key} {location}");
                return(Task.FromResult(location));
            }

            LocationQueryTask task = new LocationQueryTask(key);

            this.AddTask(key, task);
            return(task.Task);
        }
예제 #2
0
        public Task <long> GetAsync(long key)
        {
            if (!this.lockDict.ContainsKey(key))
            {
                this.locations.TryGetValue(key, out long instanceId);
                Log.Info($"location get key: {key} {instanceId}");
                return(Task.FromResult(instanceId));
            }

            LocationQueryTask task = ComponentFactory.CreateWithParent <LocationQueryTask, long>(this, key);

            this.AddTask(key, task);
            return(task.Task);
        }
예제 #3
0
        /// <summary>
        /// 异步请求位置
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public Task <long> GetAsync(long key)
        {
            if (!this.lockDict.ContainsKey(key))                      //如果这个位置没有在锁状态
            {
                this.locations.TryGetValue(key, out long instanceId); //获取字典此key的值
                Log.Info($"location get key: {key} {instanceId}");
                return(Task.FromResult(instanceId));                  //创建一个带返回值的、已完成的Task。
            }

            LocationQueryTask task = ComponentFactory.CreateWithParent <LocationQueryTask, long>(this, key);

            this.AddTask(key, task); //添加到字典中缓存 待这个地址解锁后 会自动返回其新地址
            return(task.Task);       //等待位置转换完成 返回新的位置
        }