Java API Dispatch a function to update the internal state, and return a Future where that new state can be obtained within the given timeout
Dispatch a function to update the internal state, and return a Future where that new state can be obtained within the given timeout.
Java API: Dispatch a function to update the internal state but on its own thread, and return a Future where that new state can be obtained within the given timeout.
Java API:
Dispatch a function to update the internal state but on its own thread,
and return a Future where that new state can be obtained within the given timeout.
This does not use the reactive thread pool and can be used for long-running
or blocking operations. Dispatches using either alterOff
or alter
will
still be executed in order.
Dispatch a function to update the internal state but on its own thread, and return a Future where that new state can be obtained within the given timeout.
Dispatch a function to update the internal state but on its own thread,
and return a Future where that new state can be obtained within the given timeout.
This does not use the reactive thread pool and can be used for long-running
or blocking operations. Dispatches using either alterOff
or alter
will
still be executed in order.
Read the internal state of the agent.
Gets this agent's value after all currently queued updates have completed.
Closes the agents and makes it eligible for garbage collection.
Closes the agents and makes it eligible for garbage collection.
A closed agent cannot accept any send
actions.
Java API: Flatmap this agent to a new agent, applying the function to the internal state.
Java API: Flatmap this agent to a new agent, applying the function to the internal state. Does not change the value of this agent.
Flatmap this agent to a new agent, applying the function to the internal state.
Flatmap this agent to a new agent, applying the function to the internal state. Does not change the value of this agent.
Java API: Applies the function to the internal state.
Java API: Applies the function to the internal state. Does not change the value of this agent.
Applies the function to the internal state.
Applies the function to the internal state. Does not change the value of this agent.
A future to the current value that will be completed after any currently queued updates.
Read the internal state of the agent.
Java API: Map this agent to a new agent, applying the function to the internal state.
Java API: Map this agent to a new agent, applying the function to the internal state. Does not change the value of this agent.
Map this agent to a new agent, applying the function to the internal state.
Map this agent to a new agent, applying the function to the internal state. Does not change the value of this agent.
Resumes processing of send
actions for the agent.
Java API: Dispatch a function to update the internal state.
Dispatch a new value for the internal state.
Dispatch a new value for the internal state. Behaves the same as sending a function (x => newValue).
Dispatch a function to update the internal state.
Java API: Dispatch a function to update the internal state but on its own thread.
Java API:
Dispatch a function to update the internal state but on its own thread.
This does not use the reactive thread pool and can be used for long-running
or blocking operations. Dispatches using either sendOff
or send
will
still be executed in order.
Dispatch a function to update the internal state but on its own thread.
Dispatch a function to update the internal state but on its own thread.
This does not use the reactive thread pool and can be used for long-running
or blocking operations. Dispatches using either sendOff
or send
will
still be executed in order.
Suspends processing of send
actions for the agent.
Dispatch a new value for the internal state.
Dispatch a new value for the internal state. Behaves the same as sending a function (x => newValue).
The Agent class was inspired by agents in Clojure.
Agents provide asynchronous change of individual locations. Agents are bound to a single storage location for their lifetime, and only allow mutation of that location (to a new state) to occur as a result of an action. Update actions are functions that are asynchronously applied to the Agent's state and whose return value becomes the Agent's new state. The state of an Agent should be immutable.
While updates to Agents are asynchronous, the state of an Agent is always immediately available for reading by any thread (using get or apply) without any messages.
Agents are reactive. The update actions of all Agents get interleaved amongst threads in a thread pool. At any point in time, at most one send action for each Agent is being executed. Actions dispatched to an agent from another thread will occur in the order they were sent, potentially interleaved with actions dispatched to the same agent from other sources.
If an Agent is used within an enclosing transaction, then it will participate in that transaction. Agents are integrated with the STM - any dispatches made in a transaction are held until that transaction commits, and are discarded if it is retried or aborted.
Example of usage:
Agent is also monadic, which means that you can compose operations using for-comprehensions. In monadic usage the original agents are not touched but new agents are created. So the old values (agents) are still available as-is. They are so-called 'persistent'.
Example of monadic usage: