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))); }
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) !); }
/// <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))); }
/// <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 !); } }
// 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 !); } }
public ValueTask <JsonString> ThreeXAsync() => ValueTaskEx.FromResult(Three());
public ValueTask <int> TwoXAsync(string source) => ValueTaskEx.FromResult(Two(source));
public ValueTask <string> OneXAsync(string source) => ValueTaskEx.FromResult(One(source));
public override ValueTask <Option <TValue> > TryGet(TKey key, CancellationToken cancellationToken = default) => ValueTaskEx.FromResult(Option.None <TValue>());
public ValueTask <string?> TryGetSecretAsync(string key) => ValueTaskEx.FromResult((string?)null);
public override ValueTask <TValue> GetAsync(TKey key, CancellationToken cancellationToken = default) => ValueTaskEx.FromResult(_dictionary[key]);