コード例 #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));
        }
コード例 #5
0
        // 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]);