Skip to content

Commit 4305b88

Browse files
committed
Add Counter TLDR link
1 parent 338012e commit 4305b88

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ Some aspects of the implementation are distilled from [`Jet.com` systems dating
1616
- [SqlStreamStore](https://github.com/SQLStreamStore/SQLStreamStore): Bindings for the powerful and widely used SQL-backed Event Storage system. [See SqlStreamStore docs](https://sqlstreamstore.readthedocs.io/en/latest/#introduction). :pray: [@rajivhost](https://github.com/rajivhost)
1717

1818
<a name="tldr"></a>
19-
# TL;DR :fast_forward:
19+
# TL;DR Can we cut to the chase? :fast_forward:
2020

21-
- **Dev that wants a slab of code instead of a wall of text and will guess the rest** ? :point_right: <100 LOC end to end 'tutorial' using CosmosDB: https://github.com/jet/equinox/blob/master/samples/Tutorial/Cosmos.fsx#L36
21+
- I'm a dev that wants to a flavour via _code_, any code, now! (with light commentary) :point_right: [There's a simple `Counter` example using `Equinox.MemoryStore` for you](https://github.com/jet/equinox/blob/master/samples/Tutorial/Counter.fsx#L16)
22+
- I'm a dev that knows about event sourcing, CosmosDB and F#; Throw me a terse slab of code instead of a wall of text and let me work from that! :point_right: [~100 LOC end-to-end using CosmosDB](https://github.com/jet/equinox/blob/master/samples/Tutorial/Cosmos.fsx#L36)
23+
- I understand CosmosDB backwards, show me what Equinox is going to enable that something simple I write in a few hours, or [CosmoStore](https://github.com/Dzoukr/CosmoStore) doesn't already do? :point_right: [Access Strategies guide](https://github.com/jet/equinox/blob/master/DOCUMENTATION.md#access-strategies)
2224

2325
# Features
2426

samples/Tutorial/Counter.fsx

+16-13
Original file line numberDiff line numberDiff line change
@@ -58,27 +58,30 @@ let decide command (State state) =
5858

5959
type Service internal (resolve : string -> Equinox.Stream<Event, State>) =
6060

61-
let execute counterId command : Async<unit> =
62-
let stream = resolve counterId
63-
stream.Transact(decide command)
64-
let read counterId : Async<int> =
65-
let stream = resolve counterId
66-
stream.Query(fun (State value) -> value)
67-
6861
member __.Execute(instanceId, command) : Async<unit> =
69-
execute instanceId command
62+
let stream = resolve instanceId
63+
stream.Transact(decide command)
7064
member __.Reset(instanceId, value) : Async<unit> =
71-
execute instanceId (Clear value)
65+
__.Execute(instanceId, Clear value)
7266

7367
member __.Read instanceId : Async<int> =
74-
read instanceId
68+
let stream = resolve instanceId
69+
stream.Query(fun (State value) -> value)
70+
71+
(* Out of the box, logging is via Serilog (can be wired to anything imaginable)
72+
Here we send it to the console (there's not much to see as `MemoryStore` does not do much logging) *)
73+
open Serilog
74+
let log = LoggerConfiguration().WriteTo.Console().CreateLogger()
75+
76+
(* We can integration test using an in-memory store
77+
See other examples such as Cosmos.fsx to see how we integrate with CosmosDB and/or other concrete stores *)
7578

7679
let store = Equinox.MemoryStore.VolatileStore()
7780
let codec = FsCodec.Box.Codec.Create()
7881
let resolver = Equinox.MemoryStore.Resolver(store, codec, fold, initial)
79-
open Serilog
80-
let log = LoggerConfiguration().WriteTo.Console().CreateLogger()
81-
let service = Service(fun id -> Equinox.Stream(log, streamName id |> resolver.Resolve, maxAttempts = 3))
82+
let resolve instanceId = Equinox.Stream(log, streamName instanceId |> resolver.Resolve, maxAttempts = 3)
83+
let service = Service(resolve)
84+
8285
let clientId = "ClientA"
8386
service.Read(clientId) |> Async.RunSynchronously
8487
service.Execute(clientId, Increment) |> Async.RunSynchronously

0 commit comments

Comments
 (0)