Skip to content

Commit

Permalink
update streams doc for f#
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard committed Feb 21, 2025
1 parent 5907958 commit 2ac396f
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion docs/AkkaStreamsTemplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ dotnet new -i "Akka.Templates::*"
From there, you can use this template via the following command:

```
dotnet new akka.streams -n "your project name"
# For C#
dotnet new akka.streams -n "your-project-name"
# For F#
dotnet new akka.streams -n "your-project-name" -lang F#
```

## How It Works
Expand Down Expand Up @@ -65,4 +69,42 @@ await Source.From(Enumerable.Range(1, 1000))
.RunForeach(Console.WriteLine, system); // write all output to console
```

<details>
<summary><b>F# Implementation</b></summary>

```fsharp
let hostbuilder = HostBuilder()
hostbuilder.ConfigureServices(fun services ->
services.AddAkka("MyActorSystem", fun b ->
b.WithActors(fun sys reg ->
let helloActor = sys.ActorOf(Props.Create<HelloActor>(fun () -> HelloActor()), "hello-actor")
reg.Register<HelloActor>(helloActor)) |> ignore
b.WithActors(fun sys reg resolver ->
let timerActorProps = resolver.Props<TimerActor>()
let timerActor = sys.ActorOf(timerActorProps, "timer-actor")
reg.Register<TimerActor>(timerActor)) |> ignore
) |> ignore
) |> ignore
let host = hostbuilder.Build()
host.RunAsync().Wait()
// example transform actor
type TransformActor() as this =
inherit ReceiveActor()
do
this.Receive<string> (fun (message:string)->
let actor = this :> IInternalActor
actor.ActorContext.Sender.Tell (message.ToUpper())
)
```

</details>

This is a simple, finite stream that uses some of [Akka.Streams' built-in stages](https://getakka.net/articles/streams/builtinstages.html) to demonstrate asynchronous stream processing as well as [Akka.NET actor integration with Akka.Streams](https://getakka.net/articles/streams/integration.html).

0 comments on commit 2ac396f

Please # to comment.