Advertisement
Guest User

Untitled

a guest
May 4th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. // setup actor system
  2. use system = ActorSystem.Configure()
  3. .Playground()
  4. .Register(Assembly.GetExecutingAssembly())
  5. .Done()
  6.  
  7. // get uniq actor by name
  8. let counter = system.ActorOf<Counter>("realtime-consistent-counter")
  9.  
  10. let writeJob() = task {
  11. printfn "send Increment message which should take 5 sec to finish."
  12. do! counter <! Increment // this message is not reentrant which means blocking operation
  13.  
  14. printfn "send Increment message which should take 5 sec to finish."
  15. do! counter <! Increment
  16.  
  17. printfn "send Increment message which should take 5 sec to finish."
  18. do! counter <! Increment
  19. }
  20.  
  21. let readJob() = task {
  22. let mutable count = 0
  23. while count < 3 do
  24. let! result = counter <? GetCount // this message is reentrant which means not blocking operation
  25. count <- result
  26. printfn "current value is %d" count
  27.  
  28. printfn "job is finished."
  29. }
  30.  
  31. writeJob() |> ignore
  32. Task.run(readJob) |> ignore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement