Skip to content

Instantly share code, notes, and snippets.

@isaacabraham
Last active August 29, 2015 14:26
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 isaacabraham/2e6c4691009e7239d928 to your computer and use it in GitHub Desktop.
Save isaacabraham/2e6c4691009e7239d928 to your computer and use it in GitHub Desktop.
Sample Actor interface
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