Skip to content

Instantly share code, notes, and snippets.

@rogeralsing
Created February 11, 2015 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rogeralsing/24b1fe479591965e5aea to your computer and use it in GitHub Desktop.
Save rogeralsing/24b1fe479591965e5aea to your computer and use it in GitHub Desktop.
looped state
open Akka.FSharp
open Akka
open Akka.Configuration
let system = System.create "my-system" (Configuration.defaultConfig())
let aref =
spawn system "my-actor"
(fun mailbox ->
let rec loop(state) = actor {
let! message = mailbox.Receive()
printfn "%s %A" message state
return! loop(state+1)
}
loop(0))
aref <! "hello"
aref <! "We"
aref <! "Use"
aref <! "Looped state"
@rogeralsing
Copy link
Author

This outputs

hello 0
We 1
Use 2
Looped state 3

Where the number is state that is passed around in the loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment