Skip to content

Instantly share code, notes, and snippets.

@object
Last active March 25, 2026 08:06
Show Gist options
  • Select an option

  • Save object/64468455bb861e3cb4d90831529c6cdd to your computer and use it in GitHub Desktop.

Select an option

Save object/64468455bb861e3cb4d90831529c6cdd to your computer and use it in GitHub Desktop.
Counter actor (stateful)
let counterActor (mailbox: Actor<_>) =
let rec loop lastTime countTotal countMigrated countFailed =
actor {
let! event = mailbox.Receive()
let countTotal = countTotal+1
return!
match event with
| Increment.Total currentId ->
if countTotal % 1000 = 0 then
// Omitted debug print to console
loop DateTime.Now countTotal countMigrated countFailed
else
loop lastTime countTotal countMigrated countFailed
| Increment.Migrated ->
loop lastTime countTotal (countMigrated+1) countFailed
| Increment.Failed ->
loop lastTime countTotal countMigrated (countFailed+1)
}
loop DateTime.Now 0 0 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment