These are chat archives for akkadotnet/akka.net

5th
Mar 2015
jcwrequests
@jcwrequests
Mar 05 2015 02:06
@stefansedich The release thing is based on the following post http://blog.ploeh.dk/2014/05/19/di-friendly-framework/ which I think does an excellent job explaining the need plus its an interesting read.
Stefan Sedich
@stefansedich
Mar 05 2015 02:08
You look at autofac for example
they don't have release in that way instead the request gets wrapped in a lifetime scope which itself is disposed.
Although if using autofac we could resolve an Owned<T> and in the release dispose that
would probably be enough
where T being the actor type
so yeah sorry release is probably enough :)
Raymen Scholten
@raymens
Mar 05 2015 09:19
Is there someway to append a incrementing number to an actors name that will enforce the name to be unique? (like SomeRandomActor-Child-1, ....-Child-2, ....)
Raymen Scholten
@raymens
Mar 05 2015 10:03
And is it correct that the F# API doesn't provide any F# specific stuff about creating an actor that has a constructor or any means of saving state?
Raymen Scholten
@raymens
Mar 05 2015 10:33
There are probably better ways but
let actorOfCtor (state : 'a) (fn : 'a -> 'Message -> unit) (mailbox : Actor<'Message>) : Cont<'Message, 'Returned> =
let rec loop() =  
    actor {  
        let! msg = mailbox.Receive() 
        fn state msg 
        return! loop() 
    } 
loop()
allows the creation of an actor that will have some sort of initial data that is usable by the messageHandler every message
Bartosz Sypytkowski
@Horusiath
Mar 05 2015 10:49
@raymens if you must use some state in F# API, pass it as a rec loop parameter , eg:
type MyState = { X: int; Y: int }
let aref = spawn system "my-actor" <| fun mailbox ->
    let rec loop state = actor {
         let! msg = mailbox.Receive()
         return! loop ({ state with Y = msg })
    }
    loop ({X = 1; Y = 2})
this way it maintain F# principles - immutable data, function as unit of composition etc.
Raymen Scholten
@raymens
Mar 05 2015 10:54
thanks, that's better :)