Skip to main content

Module service

Module service 

Source
Expand description

[tower::Service] integration + thread-pool.

§service

The service module implements the [tower] integration, along with the reader/writer thread-pool system.

The thread-pool allows outside crates to communicate with it by sending database Requests and receiving Responses asynchronously - without having to actually worry and handle the database themselves.

The system is managed by this crate, and only requires init by the user.

§Handles

The 2 handles to the database are:

The 1st allows any caller to send ReadRequests.

The 2nd allows any caller to send WriteRequests.

Both the handles are cheaply Cloneable.

§Initialization

The database & thread-pool system can be initialized with init_with_pool().

This causes the underlying database/threads to be setup and returns a read/write handle to that database.

§Shutdown

Upon the above handles being dropped, the corresponding thread(s) will automatically exit, i.e:

§Request and Response

To interact with the database (whether reading or writing data), a Request can be sent using one of the above handles.

Both the handles implement [tower::Service], so they can be [tower::Service::call]ed.

An asynchronous channel will be returned from the call. This channel can be .awaited upon to (eventually) receive the corresponding Response to your Request.

// TODO: we have 2 responses

Modules§

interface
Tx-pool service interface.

Structs§

TxpoolReadHandle
The txpool [Service] read handle.
TxpoolWriteHandle
The txpool [Service] write handle.

Functions§

init_with_pool
Initialise a database and return a read/write handle to it.