Last active
August 29, 2015 14:26
-
-
Save isaacabraham/2e6c4691009e7239d928 to your computer and use it in GitHub Desktop.
Sample Actor interface
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System | |
open System.Threading.Tasks | |
open Microsoft.ServiceFabric.Actors | |
/// Cat actor | |
type ICat = | |
inherit IActor | |
abstract member Jump : destination : string -> Task | |
abstract member FavouriteFood : unit -> string Task | |
abstract member Colour : unit -> string Task | |
// other members elided... | |
/// Implementation of ICat | |
type Cat() = | |
inherit Actor<CatState>() | |
let emptyTask() = Task.FromResult() :> Task // simple helper for returning Task (rather than Task<unit>) | |
interface ICat with | |
// Side-effect-free actions | |
member __.Colour() = Task.FromResult "Black" | |
member __.FavouriteFood() = Task.FromResult favouriteFood | |
// Side-effect-full actions | |
member this.Jump(destination) = | |
this.State.HungerLevel <- this.State.HungerLevel + 1 | |
this.State.CatHappiness <- this.State.CatHappiness + 1 | |
this.State.Weight <- this.State.Weight - 0.1 | |
match destination with | |
| "Table" -> this.State.OwnerHappiness <- this.State.OwnerHappiness - 2 | |
| "Bed" -> this.State.OwnerHappiness <- this.State.OwnerHappiness - 1 | |
| _ -> () | |
emptyTask() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment