public bool Success(Tval val, TimeSpan outdated_ttl, out ProCacheEntry <Tval> entry) { entry = _entry; if (_completion is null) { entry.Reset(val, outdated_ttl); return(true); } _completion.SetResult(val); entry.Reset(val, null); return(false); }
public bool Empty(TimeSpan outdated_ttl, out ProCacheEntry <Tval> entry) { entry = _entry; if (_completion is null) { entry.Reset(outdated_ttl); return(true); } entry.Reset(null); _completion.SetResult(default(Tval)); return(false); }
private async ValueTask <Tval> UpdateAsync(Tkey key, ProCacheEntry <Tval> entry, object state, CancellationToken cancellation) { try { var res = await _get(key, state, cancellation).ConfigureAwait(false); entry.Reset(res, _outdateTtl); _cache.Set(key, entry, _expireTtl); return(res); } catch { entry.Reset(); throw; } }
public bool Error(Exception ex) { if (_completion is null) { _entry.Reset(); return(false); } _completion.SetException(ex); return(true); }
public bool Success(Tval val, TimeSpan outdated_ttl, out ProCacheEntry <Tval> entry) { switch (_state) { case ResultState.Add: ((TaskCompletionSource <(bool, Tval)>)_completion).SetResult((true, val)); entry = null; return(false); case ResultState.Outdate: entry = (ProCacheEntry <Tval>)_completion; entry.Reset(val, outdated_ttl); return(true); } throw new NotImplementedException(); }