Skip to content

Commit

Permalink
Rename TransactAsync -> Transact
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Mar 4, 2022
1 parent 9869cb9 commit addfa01
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ The `Unreleased` section name is replaced by the expected version of next releas
## [Unreleased]

### Added

- `Equinox`: `Decider.Transact(interpret : 'state -> Async<'event list>)` [#308](https://github.com/jet/equinox/pull/308)

### Changed

- `eqx`/`Equinox.Tool`: Flip `-P` option to opt _in_ to pretty printing [#313](https://github.com/jet/equinox/pull/313)
- `Equinox`: rename `Decider.TransactAsync` to `Transact` [#308](https://github.com/jet/equinox/pull/308)
- `CosmosStore`: Require `Microsoft.Azure.Cosmos` v `3.0.25` [#310](https://github.com/jet/equinox/pull/310)
- `CosmosStore`: Switch to natively using `JsonElement` event bodies [#305](https://github.com/jet/equinox/pull/305) :pray: [@ylibrach](https://github.com/ylibrach)
- `CosmosStore`: Switch to natively using `System.Text.Json` for serialization of all `Microsoft.Azure.Cosmos` round-trips [#305](https://github.com/jet/equinox/pull/305) :pray: [@ylibrach](https://github.com/ylibrach)
Expand Down
13 changes: 7 additions & 6 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,7 @@ type Service internal (resolve : CartId -> Equinox.Decider<Events.Event, Fold.St
member _.Run(cartId, optimistic, commands : Command seq, ?prepare) : Async<Fold.State> =
let decider = resolve (cartId,if optimistic then Some Equinox.AllowStale else None)
decider.TransactAsync(fun state -> async {
decider.Transact(fun state -> async {
match prepare with None -> () | Some prep -> do! prep
return interpretMany Fold.fold (Seq.map interpret commands) state })
```
Expand Down Expand Up @@ -1368,7 +1368,7 @@ type Accumulator<'event, 'state>(fold : 'state -> 'event seq -> 'state, originSt
interpret __.State |> accumulated.AddRange
/// Invoke an Async decision function, gathering the events (if any) that
/// it decides are necessary into the `Accumulated` sequence
member _.TransactAsync(interpret : 'state -> Async<'event list>) : Async<unit> = async {
member _.Transact(interpret : 'state -> Async<'event list>) : Async<unit> = async {
let! events = interpret __.State
accumulated.AddRange events }
/// Invoke a decision function, while also propagating a result yielded as
Expand All @@ -1379,21 +1379,22 @@ type Accumulator<'event, 'state>(fold : 'state -> 'event seq -> 'state, originSt
result
/// Invoke a decision function, while also propagating a result yielded as
/// the fst of an (result, events) pair
member _.TransactAsync(decide : 'state -> Async<'result * 'event list>) : Async<'result> = async {
member _.Transact(decide : 'state -> Async<'result * 'event list>) : Async<'result> = async {
let! result, newEvents = decide __.State
accumulated.AddRange newEvents
return result }
type Service ... =
member _.Run(cartId, optimistic, commands : Command seq, ?prepare) : Async<Fold.State> =
let decider = resolve (cartId,if optimistic then Some Equinox.AllowStale else None)
decider.TransactAsync(fun state -> async {
let decider = resolve cartId
let opt = if optimistic then Some Equinox.AllowStale else Equinox.RequireLoad
decider.Transact(fun state -> async {
match prepare with None -> () | Some prep -> do! prep
let acc = Accumulator(Fold.fold, state)
for cmd in commands do
acc.Transact(interpret cmd)
return acc.State, acc.Accumulated
})
}, opt)
```

# Equinox Architectural Overview
Expand Down
16 changes: 8 additions & 8 deletions samples/Store/Domain/Cart.fs
Original file line number Diff line number Diff line change
Expand Up @@ -101,27 +101,27 @@ type Accumulator<'event, 'state>(fold : 'state -> 'event seq -> 'state, originSt
let accumulated = ResizeArray<'event>()

/// The Events that have thus far been pended via the `decide` functions `Execute`/`Decide`d during the course of this flow
member __.Accumulated : 'event list =
member _.Accumulated : 'event list =
accumulated |> List.ofSeq

/// The current folded State, based on the Stream's `originState` + any events that have been Accumulated during the the decision flow
member __.State : 'state =
member _.State : 'state =
accumulated |> fold originState

/// Invoke a decision function, gathering the events (if any) that it decides are necessary into the `Accumulated` sequence
member __.Transact(interpret : 'state -> 'event list) : unit =
member _.Transact(interpret : 'state -> 'event list) : unit =
interpret __.State |> accumulated.AddRange
/// Invoke an Async decision function, gathering the events (if any) that it decides are necessary into the `Accumulated` sequence
member __.TransactAsync(interpret : 'state -> Async<'event list>) : Async<unit> = async {
member _.Transact(interpret : 'state -> Async<'event list>) : Async<unit> = async {
let! events = interpret __.State
accumulated.AddRange events }
/// Invoke a decision function, while also propagating a result yielded as the fst of an (result, events) pair
member __.Transact(decide : 'state -> 'result * 'event list) : 'result =
member _.Transact(decide : 'state -> 'result * 'event list) : 'result =
let result, newEvents = decide __.State
accumulated.AddRange newEvents
result
/// Invoke a decision function, while also propagating a result yielded as the fst of an (result, events) pair
member __.TransactAsync(decide : 'state -> Async<'result * 'event list>) : Async<'result> = async {
member _.Transact(decide : 'state -> Async<'result * 'event list>) : Async<'result> = async {
let! result, newEvents = decide __.State
accumulated.AddRange newEvents
return result }
Expand All @@ -138,13 +138,13 @@ type Service internal (resolve : CartId * Equinox.ResolveOption option -> Equino

member __.Run(cartId, optimistic, commands : Command seq, ?prepare) : Async<Fold.State> =
let decider = resolve (cartId,if optimistic then Some Equinox.AllowStale else None)
decider.TransactAsync(fun state -> async {
decider.Transact(fun state -> async {
match prepare with None -> () | Some prep -> do! prep
#if ACCUMULATOR
let acc = Accumulator(Fold.fold, state)
for cmd in commands do
acc.Transact(interpret cmd)
return acc.State, acc.Accumulated })
return acc.State, acc.Accumulated }
#else
return interpretMany Fold.fold (Seq.map interpret commands) state })
#endif
Expand Down
2 changes: 1 addition & 1 deletion samples/Store/Domain/SavedForLater.fs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ type Service internal (resolve : ClientId -> Equinox.Decider<Events.Event, Fold.

let remove clientId (resolveCommand : ((SkuId->bool) -> Async<Command>)) : Async<unit> =
let decider = resolve clientId
decider.TransactAsync(fun (state : Fold.State) -> async {
decider.Transact(fun (state : Fold.State) -> async {
let contents = seq { for item in state -> item.skuId } |> set
let! cmd = resolveCommand contents.Contains
let _, events = decide maxSavedItems cmd state
Expand Down
6 changes: 3 additions & 3 deletions src/Equinox/Decider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ type Decider<'event, 'state>
/// 1a. (if events yielded) Attempt to sync the yielded events events to the stream
/// 1b. Tries up to <c>maxAttempts</c> times in the case of a conflict, throwing <c>MaxResyncsExhaustedException</c> to signal failure.
/// 2. Yield result
member _.TransactAsync(decide : 'state -> Async<'result * 'event list>) : Async<'result> =
member _.Transact(decide : 'state -> Async<'result * 'event list>) : Async<'result> =
transact (fun context -> decide context.State) (fun result _context -> result)

/// 0. Invoke the supplied <c>_Async_</c> <c>decide</c> function with the present state (including extended context), holding the <c>'result</c>
/// 1a. (if events yielded) Attempt to sync the yielded events events to the stream
/// 1b. Tries up to <c>maxAttempts</c> times in the case of a conflict, throwing <c>MaxResyncsExhaustedException</c> to signal failure.
/// 2. Uses <c>mapResult</c> to render the final outcome from the <c>'result</c> and/or the final <c>ISyncContext</c>
/// 3. Yields the outcome
/// 2. Uses <c>mapResult</c> to render the final 'view from the <c>'result</c> and/or the final <c>ISyncContext</c>
/// 3. Yields the 'view
member _.TransactEx(decide : ISyncContext<'state> -> Async<'result * 'event list>, mapResult : 'result -> ISyncContext<'state> -> 'view) : Async<'view> =
transact decide mapResult

Expand Down
2 changes: 1 addition & 1 deletion tests/Equinox.CosmosStore.Integration/AccessStrategies.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ module SequenceCheck =

member _.Add(instance : Guid, value : int, count) : Async<int array> =
let decider = resolve instance
decider.TransactEx((fun c -> async { return (), decide (value, count) c.State }), (fun () c -> c.State))
decider.TransactEx((fun c -> async { return (), decide (value, count) c.State }), fun () c -> c.State)

let private create log resolveStream =
let resolve = streamName >> resolveStream >> (createDecider log)
Expand Down

0 comments on commit addfa01

Please sign in to comment.