Skip to content

Commit

Permalink
Add Counter TLDR link
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Mar 23, 2020
1 parent 338012e commit ac7e783
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<a name="tldr"></a>
# 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# wants a more complext slab of code instead of a wall of text and will guess the rest ? :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, what is Equinox going to enable that something simple I write in a few hours, or [CosmoStore](https://github.com/Dzoukr/CosmoStore) would? :point_right: [Access Strategies guide](https://github.com/jet/equinox/blob/master/DOCUMENTATION.md#access-strategies)

# Features

Expand Down
29 changes: 16 additions & 13 deletions samples/Tutorial/Counter.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,30 @@ let decide command (State state) =

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

let execute counterId command : Async<unit> =
let stream = resolve counterId
stream.Transact(decide command)
let read counterId : Async<int> =
let stream = resolve counterId
stream.Query(fun (State value) -> value)

member __.Execute(instanceId, command) : Async<unit> =
execute instanceId command
let stream = resolve instanceId
stream.Transact(decide command)
member __.Reset(instanceId, value) : Async<unit> =
execute instanceId (Clear value)
__.Execute(instanceId, Clear value)

member __.Read instanceId : Async<int> =
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
Expand Down

0 comments on commit ac7e783

Please sign in to comment.