|
Action Engine
|
An asynchronous node in the ActionEngine framework.
This class represents a node that can read and write data asynchronously. It provides methods for consuming data as specific types. The node is backed by a ChunkStore for storing data chunks.
#include <actionengine/nodes/async_node.h>
Public Member Functions | |
| AsyncNode (std::string_view id="", NodeMap *absl_nullable node_map=nullptr, std::unique_ptr< ChunkStore > chunk_store=nullptr) | |
| auto | Put (Chunk value, int seq=-1, bool final=false) -> absl::Status |
| auto | Put (NodeFragment value) -> absl::Status |
| template<typename T> | |
| auto | Put (T value, int seq=-1, bool final=false) -> absl::Status |
| ChunkStoreWriter & | GetWriter () |
| auto | GetWriterStatus () const -> absl::Status |
| absl::StatusOr< std::optional< Chunk > > | Next (std::optional< absl::Duration > timeout=std::nullopt) |
|
explicit |
Constructs an AsyncNode with the given ID, node map, and chunk store.
| id | The unique identifier for the node. |
| node_map | An optional pointer to a NodeMap for managing multiple nodes. |
| chunk_store | An optional unique pointer to a ChunkStore for storing data chunks. If not provided, a default chunk store will be created. |
|
nodiscard |
Returns the writer for this AsyncNode.
This method ensures that a writer is created if it does not already exist, so never fails.
|
nodiscard |
Returns the status of the writer for this AsyncNode.
This method checks if the writer is in a valid state and returns an absl::Status indicating the status of the writer.
absl::Status indicating the status of the writer. If the writer is in a valid state, it returns absl::OkStatus(). If there is an error, it returns an appropriate error status. | absl::StatusOr< std::optional< Chunk > > act::AsyncNode::Next | ( | std::optional< absl::Duration > | timeout = std::nullopt | ) |
Reads the next chunk from the underlying chunk store.
This method reads the next chunk from the store, blocking until a chunk is available or the timeout expires. If no chunk is available within the timeout, it returns an empty optional.
The default associated reader is used, but multiple readers in principle can be created for the same AsyncNode, each with its own options.
| timeout | An optional duration to wait for a chunk to become available. If not provided, it defaults to the reader's timeout. |
absl::StatusOr containing an optional Chunk. If a chunk is available, it will be returned; otherwise, an empty optional is returned. | auto act::AsyncNode::Put | ( | Chunk | value, |
| int | seq = -1, | ||
| bool | final = false ) -> absl::Status |
Enqueues a chunk to be written to underlying chunk store.
| value | The chunk to write to the store. |
| seq | The sequence number of the chunk. If -1, the chunk will be written without a specific sequence number. |
| final | A flag indicating whether this is the final chunk in a sequence. If true, the chunk will be marked as final, and no more chunks are expected after this one. |
| auto act::AsyncNode::Put | ( | NodeFragment | value | ) | -> absl::Status |
Enqueues a NodeFragment to be written to the underlying chunk store.
See Put(Chunk, int, bool) for details on the parameters, which in this case are part of the NodeFragment structure.
| value | The NodeFragment to write to the store. |
| auto act::AsyncNode::Put | ( | T | value, |
| int | seq = -1, | ||
| bool | final = false ) -> absl::Status |
Enqueues a value to be written to the underlying chunk store.
This method converts the value to a Chunk using ToChunk and then calls Put(Chunk, int, bool) with the converted chunk.
| value | The value to write to the store. |
| seq | The sequence number of the chunk. If -1, the chunk will be written without a specific sequence number. |
| final | A flag indicating whether this is the final chunk in a sequence. |