示例#1
0
        public static async Task <T> SyncronizedExecute <T>(this T command, Func <Task <WebSocket> > transport, JsonSerializer serializer, long queueKey = 0) where T : INetworkCommand
        {
            string key = $"SyncronizedExecute_{queueKey}";
            bool   retry = true, manualUnlock = false;

            while (true)
            {
                try {
                    RequestLockManager.LockAndWait(key);
                    bool tmpManualUnlock = command.RequestManualUnlock(() => RequestLockManager.Unlock(key));
                    await command.ExecuteClientSyncronizedCommand(serializer, transport);

                    manualUnlock = tmpManualUnlock;
                    retry        = false;
                    return(command);
                } catch {
                } finally {
                    if (!manualUnlock)
                    {
                        RequestLockManager.Unlock(key);
                    }
                    if (retry)
                    {
                        await Task.Yield();
                    }
                }
            }
        }
示例#2
0
        public DocumentPredictor(IDocumentStore store, IDocumentPredictor predictor, ICacheAllocator allocator, ChainedFileSystem predictOnFileSystem)
        {
            Store     = store;
            Predictor = predictor;
            Allocator = allocator;

            Allocator.OnDeallocate.Add(async(x) => {
                await Store.Remove(x);
            });
            ThreadPool.QueueUserWorkItem(async(x) => {
                try {
                    RequestLockManager.LockAndWait("DocumentPredictor_ctor");
                    while (FileSystem == null)
                    {
                        await Task.Delay(10);
                    }
                    await PredicitiveFillCache(0, CancellationToken.None);
                }finally{
                    RequestLockManager.Unlock("DocumentPredictor_ctor");
                }
            });
        }