Пример #1
0
 protected override ValueTask <Option <string> > Load(string key, CancellationToken cancellationToken)
 {
     if (!Storage.TryGetValue(key, out var value))
     {
         return(ValueTaskEx.FromResult(Option.None <string>()));
     }
     ExpirationTimers.AddOrUpdateToLater(key, Clock.Now + ExpirationTime);
     return(ValueTaskEx.FromResult(Option.Some(value)));
 }
Пример #2
0
 protected override ValueTask <string?> Load(string key, CancellationToken cancellationToken)
 {
     if (!Storage.TryGetValue(key, out var value))
     {
         return(ValueTaskEx.FromResult((string?)null));
     }
     ExpirationTimers.AddOrUpdateToLater(key, Clock.Now + ExpirationTime);
     return(ValueTaskEx.FromResult(value) !);
 }
Пример #3
0
        /// <inheritdoc/>
        public ValueTask <IFileSystemEntry> GetFileAsync(string name, CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(ValueTaskEx.FromCanceled <IFileSystemEntry>(cancellationToken));
            }

            IFileInfo file = this.fileProvider.GetFileInfo(ToFilePath(name));

            if (!file.Exists)
            {
                return(ValueTaskEx.FromResult <IFileSystemEntry>(null));
            }

            return(ValueTaskEx.FromResult <IFileSystemEntry>(new PhysicalFileSystemEntry(file, this.contentTypeProvider)));
        }
Пример #4
0
        /// <inheritdoc/>
        public ValueTask <bool> TryDeleteFileAsync(string name, CancellationToken cancellationToken = default)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                return(ValueTaskEx.FromCanceled <bool>(cancellationToken));
            }

            IFileInfo file = this.fileProvider.GetFileInfo(ToFilePath(name));

            if (!file.Exists)
            {
                return(ValueTaskEx.FromResult(false));
            }

            File.Delete(file.PhysicalPath);
            return(ValueTaskEx.FromResult(true));
        }
        // Protected methods

        protected static void SetReturnValue(InterceptedInput input, Result <TOut> output)
        {
            if (input.Method.ReturnsValueTask)
            {
                input.Invocation.ReturnValue =
                    output.IsValue(out var v)
                        ? ValueTaskEx.FromResult(v)
                        : ValueTaskEx.FromException <TOut>(output.Error !);
            }
            else
            {
                input.Invocation.ReturnValue =
                    output.IsValue(out var v)
                        ? Task.FromResult(v)
                        : Task.FromException <TOut>(output.Error !);
            }
        }
Пример #6
0
        // Protected methods

        protected static void SetReturnValue(ComputeMethodInput input, Result <TOut> output)
        {
            if (input.Method.ReturnsValueTask)
            {
                input.Invocation.ReturnValue =
                    // ReSharper disable once HeapView.BoxingAllocation
                    output.IsValue(out var v)
                        ? ValueTaskEx.FromResult(v)
                        : ValueTaskEx.FromException <TOut>(output.Error !);
            }
            else
            {
                input.Invocation.ReturnValue =
                    output.IsValue(out var v)
                        ? Task.FromResult(v)
                        : Task.FromException <TOut>(output.Error !);
            }
        }
Пример #7
0
 public ValueTask <JsonString> ThreeXAsync()
 => ValueTaskEx.FromResult(Three());
Пример #8
0
 public ValueTask <int> TwoXAsync(string source)
 => ValueTaskEx.FromResult(Two(source));
Пример #9
0
 public ValueTask <string> OneXAsync(string source)
 => ValueTaskEx.FromResult(One(source));
Пример #10
0
 public override ValueTask <Option <TValue> > TryGet(TKey key, CancellationToken cancellationToken = default)
 => ValueTaskEx.FromResult(Option.None <TValue>());
Пример #11
0
 public ValueTask <string?> TryGetSecretAsync(string key)
 => ValueTaskEx.FromResult((string?)null);
Пример #12
0
 public override ValueTask <TValue> GetAsync(TKey key, CancellationToken cancellationToken = default)
 => ValueTaskEx.FromResult(_dictionary[key]);