Skip to content

Commit 30092d5

Browse files
authored
refactor!: Rename AsyncLazy/CacheCell -> LazyTask/TaskCell (#433)
1 parent 6ffcbac commit 30092d5

File tree

12 files changed

+32
-31
lines changed

12 files changed

+32
-31
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ The `Unreleased` section name is replaced by the expected version of next releas
4242
- `Equinox.Decider`: Replace `maxAttempts` with a default policy and an optional argument on `Transact*` APIs [#337](https://github.com/jet/equinox/pull/337)
4343
- `Equinox.Decider`: rename `Decider.TransactAsync`, `Decider.TransactExAsync` to `Transact` [#314](https://github.com/jet/equinox/pull/314)
4444
- `Equinox.Core.AsyncBatchingGate`: renamed to `Batching.Batcher` [#390](https://github.com/jet/equinox/pull/390)
45-
- `Equinox.Core`: Now a free-standing library that a) does not depend on `Equinox` b) is not depended on by the Stores (though `CosmosStore` inlines `AsyncCacheCell`) [#420](https://github.com/jet/equinox/pull/420)
45+
- `Equinox.Core.AsyncCacheCell`: renamed to `TaskCell` [#433](https://github.com/jet/equinox/pull/433)
46+
- `Equinox.Core`: Now a free-standing library that a) does not depend on `Equinox` b) is not depended on by the Stores (though `CosmosStore` inlines `TaskCell`) [#420](https://github.com/jet/equinox/pull/420)
4647
- Stores: Change Event Body types, requiring `FsCodec` v `3.0.0`, with [`EventBody` types switching from `byte[]` to `ReadOnlyMemory<byte>` and/or `JsonElement` see FsCodec#75](https://github.com/jet/FsCodec/pull/75) [#323](https://github.com/jet/equinox/pull/323)
4748
- Stores: `*Category.Resolve`: Replace `Resolve(sn, ?ResolveOption, ?requestContext)` with `?load = LoadOption` parameter on all `Transact` and `Query` methods, and `Decider.forStream`/`Decider.forRequest` to convey request context [#308](https://github.com/jet/equinox/pull/308)
4849
- Stores: `*Category` ctor: Add mandatory `name` argument, and `Name` property [#410](https://github.com/jet/equinox/pull/410)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ The components within this repository are delivered as multi-targeted Nuget pack
168168

169169
## Data Store libraries
170170

171-
- `Equinox.Core` [![NuGet](https://img.shields.io/nuget/v/Equinox.Core.svg)](https://www.nuget.org/packages/Equinox.Core/): Hosts generic utility types frequently useful alongside Equinox: [`AsyncCacheCell`](https://github.com/jet/equinox/blob/master/src/Equinox.Core/AsyncCacheCell.fs#L36), [`Batcher`, `BatcherCache`, `BatcherDictionary`](https://github.com/jet/equinox/blob/master/src/Equinox.Core/Batching.fs#L44). ([depends](https://www.fuget.org/packages/Equinox.Core) on `System.Runtime.Caching`)
171+
- `Equinox.Core` [![NuGet](https://img.shields.io/nuget/v/Equinox.Core.svg)](https://www.nuget.org/packages/Equinox.Core/): Hosts generic utility types frequently useful alongside Equinox: [`TaskCell`](https://github.com/jet/equinox/blob/master/src/Equinox.Core/TaskCell.fs#L36), [`Batcher`, `BatcherCache`, `BatcherDictionary`](https://github.com/jet/equinox/blob/master/src/Equinox.Core/Batching.fs#L44). ([depends](https://www.fuget.org/packages/Equinox.Core) on `System.Runtime.Caching`)
172172
- `Equinox.MemoryStore` [![MemoryStore NuGet](https://img.shields.io/nuget/v/Equinox.MemoryStore.svg)](https://www.nuget.org/packages/Equinox.MemoryStore/): In-memory store for integration testing/performance base-lining/providing out-of-the-box zero dependency storage for examples. ([depends](https://www.fuget.org/packages/Equinox.MemoryStore) on `Equinox`)
173173
- `Equinox.CosmosStore` [![CosmosStore NuGet](https://img.shields.io/nuget/v/Equinox.CosmosStore.svg)](https://www.nuget.org/packages/Equinox.CosmosStore/): Azure CosmosDB Adapter with integrated 'unfolds' feature, facilitating optimal read performance in terms of latency and RU costs, instrumented to meet Jet's production monitoring requirements. ([depends](https://www.fuget.org/packages/Equinox.CosmosStore) on `Equinox`, `Equinox`, `Microsoft.Azure.Cosmos` >= `3.27`, `System.Text.Json`, `FSharp.Control.TaskSeq`)
174174
- `Equinox.CosmosStore.Prometheus` [![CosmosStore.Prometheus NuGet](https://img.shields.io/nuget/v/Equinox.CosmosStore.Prometheus.svg)](https://www.nuget.org/packages/Equinox.CosmosStore.Prometheus/): Integration package providing a `Serilog.Core.ILogEventSink` that extracts detailed metrics information attached to the `LogEvent`s and feeds them to the `prometheus-net`'s `Prometheus.Metrics` static instance. ([depends](https://www.fuget.org/packages/Equinox.CosmosStore.Prometheus) on `Equinox.CosmosStore`, `prometheus-net >= 3.6.0`)

src/Equinox.Core/Equinox.Core.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
<ItemGroup>
99
<Compile Include="..\Equinox\Infrastructure.fs" />
10-
<Compile Include="..\Equinox\AsyncLazy.fs" />
11-
<Compile Include="AsyncCacheCell.fs" />
10+
<Compile Include="..\Equinox\LazyTask.fs" />
11+
<Compile Include="TaskCell.fs" />
1212
<Compile Include="Retry.fs" />
1313
<Compile Include="Batching.fs" />
1414
</ItemGroup>
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ type
99
// PUBLIC in Equinox.Core (it can also be used independent of Equinox)
1010
internal
1111
#endif
12-
AsyncCacheCell<'T>(startWorkflow : System.Func<CancellationToken, Task<'T>>, [<O; D null>]?isExpired: System.Func<'T, bool>) =
12+
TaskCell<'T>(startWorkflow : System.Func<CancellationToken, Task<'T>>, [<O; D null>]?isExpired: System.Func<'T, bool>) =
1313

1414
let isValid = match isExpired with Some f -> not << f.Invoke | None -> fun _ -> true
15-
let mutable cell = AsyncLazy<'T>.Empty
15+
let mutable cell = LazyTask<'T>.Empty
1616

1717
/// Synchronously check the value remains valid (to enable short-circuiting an Await step where value not required)
1818
member _.IsValid() =
@@ -26,7 +26,7 @@ type
2626
| ValueSome res when isValid res -> return res
2727
| _ ->
2828
// Prepare a new instance, with cancellation under our control (it won't start until the first Await on the LazyTask triggers it though)
29-
let newInstance = AsyncLazy<'T>(fun () -> startWorkflow.Invoke ct)
29+
let newInstance = LazyTask<'T>(fun () -> startWorkflow.Invoke ct)
3030
// If there are concurrent executions, the first through the gate wins; everybody else awaits the instance the winner wrote
3131
let _ = Interlocked.CompareExchange(&cell, newInstance, current)
3232
return! cell.Await() }

src/Equinox.CosmosStore/CosmosStore.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ module Initialization =
577577

578578
/// Per Container, we need to ensure the stored procedure has been created exactly once (per process lifetime)
579579
type internal ContainerInitializerGuard(container: Container, ?initContainer: Container -> CancellationToken -> Task<unit>) =
580-
let initGuard = initContainer |> Option.map (fun init -> AsyncCacheCell<unit>(init container))
580+
let initGuard = initContainer |> Option.map (fun init -> TaskCell<unit>(init container))
581581
member val Container = container
582582
/// Coordinates max of one in flight call to the init logic, retrying on next request if it fails. Calls after it has succeeded noop
583583
member _.Initialize(ct): System.Threading.Tasks.ValueTask =

src/Equinox.CosmosStore/Equinox.CosmosStore.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
<ItemGroup>
88
<Compile Include="..\Equinox\Infrastructure.fs" />
9-
<Compile Include="..\Equinox\AsyncLazy.fs" />
10-
<Compile Include="..\Equinox.Core\AsyncCacheCell.fs" />
9+
<Compile Include="..\Equinox\LazyTask.fs" />
10+
<Compile Include="..\Equinox.Core\TaskCell.fs" />
1111
<Compile Include="..\Equinox.Core\Internal.fs" />
1212
<Compile Include="CosmosStoreSerialization.fs" />
1313
<Compile Include="CosmosStore.fs" />

src/Equinox/Cache.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type private CacheEntry<'state>(initialToken: StreamToken, initialState: 'state,
1515
let tryGet () =
1616
if verifiedTimestamp = 0L then ValueNone // 0 => Null cache entry
1717
else ValueSome (struct (currentToken, currentState))
18-
let mutable cell = AsyncLazy<struct(int64 * (struct (StreamToken * 'state)))>.Empty
18+
let mutable cell = LazyTask<struct(int64 * (struct (StreamToken * 'state)))>.Empty
1919
static member CreateEmpty() =
2020
new CacheEntry<'state>(Unchecked.defaultof<StreamToken>, Unchecked.defaultof<'state>, 0L) // 0 => Null cache entry signifies token and state both invalid
2121
/// Attempt to retrieve the cached state, and associated token (ValueNone if this is a placeholder entry that's yet to complete its first Load operation)
@@ -31,7 +31,7 @@ type private CacheEntry<'state>(initialToken: StreamToken, initialState: 'state,
3131
if verifiedTimestamp < timestamp then // Don't count attempts to overwrite with stale state as verification
3232
verifiedTimestamp <- timestamp
3333
/// Coordinates having a max of one in-flight request across all staleness-tolerant loads at all times
34-
// Follows high level flow of AsyncCacheCell.Await - read the comments there, and the AsyncCacheCell tests first!
34+
// Follows high level flow of TaskCell.Await - read the comments there, and the TaskCell tests first!
3535
member x.ReadThrough(maxAge: TimeSpan, isStale, load: Func<_, _>) = task {
3636
let cacheEntryValidityCheckTimestamp = System.Diagnostics.Stopwatch.GetTimestamp()
3737
let isWithinMaxAge cachedValueTimestamp = Stopwatch.TicksToSeconds(cacheEntryValidityCheckTimestamp - cachedValueTimestamp) <= maxAge.TotalSeconds
@@ -47,7 +47,7 @@ type private CacheEntry<'state>(initialToken: StreamToken, initialState: 'state,
4747
| _ ->
4848

4949
// .. it wasn't; join the race to dispatch a request (others following us will share our fate via the TryAwaitValid)
50-
let newInstance = AsyncLazy(fun () -> load.Invoke maybeBaseState)
50+
let newInstance = LazyTask(fun () -> load.Invoke maybeBaseState)
5151
let _ = Interlocked.CompareExchange(&cell, newInstance, ourInitialCellState)
5252
let! timestamp, (token, state as res) = cell.Await()
5353
x.MergeUpdates(isStale, timestamp, token, state) // merge observed result into the cache

src/Equinox/Equinox.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Compile Include="Stream.fs" />
1212
<Compile Include="Decider.fs" />
1313
<Compile Include="Category.fs" />
14-
<Compile Include="AsyncLazy.fs" />
14+
<Compile Include="LazyTask.fs" />
1515
<Compile Include="Cache.fs" />
1616
<Compile Include="Caching.fs" />
1717
</ItemGroup>
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ namespace Equinox.Core
44
type
55
#if !EQUINOX_CORE
66
// NOT PUBLIC in Equinox library - used internally in the impl of CacheEntry
7-
// PUBLIC in Equinox.Core (which also uses it in the impl of AsyncCacheCell)
7+
// PUBLIC in Equinox.Core (which also uses it in the impl of TaskCell)
88
internal
99
#endif
10-
AsyncLazy<'T>(startTask: System.Func<Task<'T>>) =
11-
// NOTE due to `Lazy<T>` semantics, failed attempts will cache any exception; AsyncCacheCell compensates for this by rolling over to a new instance
10+
LazyTask<'T>(startTask: System.Func<Task<'T>>) =
11+
// NOTE due to `Lazy<T>` semantics, failed attempts will cache any exception; TaskCell compensates for this by rolling over to a new instance
1212
let workflow = lazy startTask.Invoke()
1313

1414
/// Synchronously peek at what's been previously computed (if it's not Empty, or the last attempt Faulted).
@@ -33,4 +33,4 @@ type
3333
member _.Await() = workflow.Value
3434

3535
/// Singleton Empty value
36-
static member val Empty = AsyncLazy(fun () -> Task.FromException<'T>(System.InvalidOperationException "Uninitialized AsyncLazy"))
36+
static member val Empty = LazyTask(fun () -> Task.FromException<'T>(System.InvalidOperationException "Uninitialized LazyTask"))

tests/Equinox.Core.Tests/Equinox.Core.Tests.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
<ItemGroup>
88
<Compile Include="..\..\src\Equinox\Infrastructure.fs" />
9-
<Compile Include="AsyncLazyTests.fs" />
10-
<Compile Include="AsyncCacheCellTests.fs" />
9+
<Compile Include="LazyTaskTests.fs" />
10+
<Compile Include="TaskCellTests.fs" />
1111
<Compile Include="BatchingTests.fs" />
1212
</ItemGroup>
1313

0 commit comments

Comments
 (0)