Akkling

repository·master·Indexed 42 days ago

https://github.com/horusiath/akkling

An experimental F# fork of Akka.FSharp that provides a simplified API and introduces statically typed actor references (aref) to ensure message types match at compile time.

Tokens
615
Snippets
2
Records
3
Agent score
4%

What's inside Akkling

  1. Overview of Akkling

    master
    Akkling is an experimental fork of the Akka.FSharp library. It aims to simplify the existing Akka.FSharp API and introduce new features, most notably statically typed actor references (aref). This fork allows for the introduction of experimental and potentially breaking changes independently of the official Akka release cycle.
  2. Quickstart: Create a basic Actor System and spawn an anonymous actor

    master

    To get started with Akkling, you first create an actor system using System.create with a configuration. You can then spawn an anonymous actor using spawnAnonymous. Because Akkling supports typed actor references, the messages sent to the actor must match the type defined in the actorOf function. Attempting to send a message of a different type will result in a static type error.

    open Akkling
    
    use system = System.create "my-system" <| Configuration.defaultConfig()
    let aref = spawnAnonymous system <| props(actorOf (fun m -> printfn "%s" m |> ignored))
    
    aref <! "hello world"
    // aref <! 1 // This would cause a static type error because the actor expects strings
  3. Use stateful actors with the `become` pattern

    master

    Akkling supports stateful actors by using the become function to change the actor's behavior (the function handling messages) dynamically. This is a common pattern for implementing state machines in actors.

    open Akkling
    
    use system = System.create "my-system" <| Configuration.defaultConfig()
    
    type Message =
        | Hi
        | Greet of string
    
    let rec greeter lastKnown = function
        | Hi -> printfn "Who sent Hi? %s?" lastKnown |> ignored
        | Greet(who) ->
            printfn "%s sends greetings" who
            become (greeter who)
    
    let aref = spawn system "greeter" <| props(actorOf (greeter "Unknown"))
    
    aref <! Greet "Tom"
    aref <! Greet "Jane"
    aref <! Hi