Skip to content

Instantly share code, notes, and snippets.

@chillitom
Created November 20, 2015 11:53
Show Gist options
  • Save chillitom/3d3a4294fa4f4030f805 to your computer and use it in GitHub Desktop.
Save chillitom/3d3a4294fa4f4030f805 to your computer and use it in GitHub Desktop.
playing with Akka.Persistence.FSharp's persistent view's manual updates
open System
open Akka.FSharp
open Akka.Persistence
open Akka.Persistence.FSharp
let system = System.create "sys" (Configuration.parse("""
akka.persistence.view.auto-update = off
"""))
type Query = Query
let s0 =
spawnPersist system "s0" {
state = []
apply = fun m s e -> e::s
exec = fun m s e -> m.PersistEvent (fun e -> e::s) [e]
} []
let s0v =
spawnView system "s0v" "s0" {
state = ""
apply = fun (mailbox:View<obj,string>) state (e:obj) ->
match e with
| :? string as s -> state + (s.ToUpper())
| :? Query ->
mailbox.Sender() <! state
state
| _ -> state
} []
s0v <? Query |> Async.RunSynchronously |> printfn "%s"
s0 <! "foo"
s0 <! "bar"
s0 <! "baz"
s0v <? Query |> Async.RunSynchronously |> printfn "%s"
s0v <! Update()
s0v <? Query |> Async.RunSynchronously |> printfn "%s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment