forked from OrleansContrib/Orleankka
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.fs
More file actions
58 lines (41 loc) · 1.57 KB
/
Program.fs
File metadata and controls
58 lines (41 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
open System
open System.Reflection
open Orleankka
open Orleankka.FSharp
open Orleankka.Playground
open Shop
open Account
[<EntryPoint>]
let main argv =
printfn "Running demo. Booting cluster might take some time ...\n"
use system = ActorSystem.Configure()
.Playground()
.Register(Assembly.GetExecutingAssembly())
.Done()
let shop = system.ActorOf<Shop>("Amazon")
let account = system.ActorOf<Account>("Antya")
let job() = task {
let! stock = shop <? Stock
printfn "Shop has %i items in stock \n" stock
let! balance = account <? Balance
printfn "Account balance is %i \n" balance
printfn "Let's put 100$ on the account \n"
do! account <! Deposit(100)
printfn "Let's put 5 items in stock \n"
do! shop <! CheckIn(5)
let! stock = shop <? Stock
printfn "Now shop has %i items in stock \n" stock
try
printfn "Let's sell 100 items to user \n"
do! shop <! Sell(account, 100)
with :? InvalidOperationException as e -> printf "[Exception]: %s \n" e.Message
printfn "Let's sell 2 items to user \n"
do! shop <! Sell(account, 2)
let! stock = shop <? Stock
printfn "Now shop has %i items in stock \n" stock
let! balance = account <? Balance
printfn "And account balance is %i \n" balance
}
Task.run(job) |> ignore
Console.ReadLine() |> ignore
0