practicalli / practicalli/clojure

Agents

Open
#9 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Makefile
Stars
117
Forks
36
PR merge metrics
No merged PRs in 30d

Description

A bank account with balance 100.00
Receive 20 request to withdraw $100.00

In Java you need to lock the resource as soon as the first request arrives, so that only the first one can be made and all the others fail.

I saw examples using the actor model were you can use a single actor to represent one account, and so the 20 requests would be made by the account actor, leading to the expected result
Does Clojure have any way on helping with this? I saw about the agents but i couldn’t find any information that i could digest on this.

Clojure Agents are a straightforward way to do something much like an actor, the important difference being that an actor is a method that you send data to, and an agent is data you send a function to

Set a validator so an the action won't succeed if it leaves a balance below 0 for example
you can also do this with atoms, which are much more intuitive to use

With multiple processes you need inter-process communication. It's also IPC if you ever reboot the VM (two processes, at different times, working on the same data world)

you can use refs to coordinate multiple stateful changes https://clojure.org/reference/refs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no repository file, test, or entry point; it asks how Clojure Agents, atoms, and refs relate to actor-style account updates. Start with the linked Clojure refs documentation and the concepts named in the issue. Done is not defined because no documentation change or specific deliverable is requested.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure
Domain
documentation
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.