From 4305b882cbffdc2ad6b819c7895bd1ff9041070e Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Mon, 23 Mar 2020 15:02:48 +0000 Subject: [PATCH] Add Counter TLDR link --- README.md | 6 ++++-- samples/Tutorial/Counter.fsx | 29 ++++++++++++++++------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 1e6bb8b4e..810dd8f29 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,11 @@ Some aspects of the implementation are distilled from [`Jet.com` systems dating - [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) -# TL;DR :fast_forward: +# TL;DR Can we cut to the chase? :fast_forward: -- **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 +- 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) +- 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) +- 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) # Features diff --git a/samples/Tutorial/Counter.fsx b/samples/Tutorial/Counter.fsx index 755ce587a..e74008777 100644 --- a/samples/Tutorial/Counter.fsx +++ b/samples/Tutorial/Counter.fsx @@ -58,27 +58,30 @@ let decide command (State state) = type Service internal (resolve : string -> Equinox.Stream) = - let execute counterId command : Async = - let stream = resolve counterId - stream.Transact(decide command) - let read counterId : Async = - let stream = resolve counterId - stream.Query(fun (State value) -> value) - member __.Execute(instanceId, command) : Async = - execute instanceId command + let stream = resolve instanceId + stream.Transact(decide command) member __.Reset(instanceId, value) : Async = - execute instanceId (Clear value) + __.Execute(instanceId, Clear value) member __.Read instanceId : Async = - read instanceId + let stream = resolve instanceId + stream.Query(fun (State value) -> value) + +(* Out of the box, logging is via Serilog (can be wired to anything imaginable) + Here we send it to the console (there's not much to see as `MemoryStore` does not do much logging) *) +open Serilog +let log = LoggerConfiguration().WriteTo.Console().CreateLogger() + +(* We can integration test using an in-memory store + See other examples such as Cosmos.fsx to see how we integrate with CosmosDB and/or other concrete stores *) let store = Equinox.MemoryStore.VolatileStore() let codec = FsCodec.Box.Codec.Create() let resolver = Equinox.MemoryStore.Resolver(store, codec, fold, initial) -open Serilog -let log = LoggerConfiguration().WriteTo.Console().CreateLogger() -let service = Service(fun id -> Equinox.Stream(log, streamName id |> resolver.Resolve, maxAttempts = 3)) +let resolve instanceId = Equinox.Stream(log, streamName instanceId |> resolver.Resolve, maxAttempts = 3) +let service = Service(resolve) + let clientId = "ClientA" service.Read(clientId) |> Async.RunSynchronously service.Execute(clientId, Increment) |> Async.RunSynchronously