Skip to content

Commit

Permalink
Added TaskResult Generic
Browse files Browse the repository at this point in the history
Added a new generic as the return type for the underlying task, allowing
the task itself to return data.
  • Loading branch information
KennethWilke committed Jun 18, 2022
1 parent 41c522c commit 79a1d4a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tenorite"
version = "0.1.2"
version = "0.1.3"
authors = ["Kenneth Wilke <kenneth.wilke@gmail.com>"]
edition = "2021"
description = "A concurrency abstraction library. Provides a client-server model for asynchronous workers"
Expand Down
9 changes: 5 additions & 4 deletions src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,25 @@ use super::caller::TenoriteCaller;
use super::worker::TenoriteWorker;

/// Binds together the generic type components into the service
pub trait TenoriteService<Request, Response, Error, Task, TaskConfig>
pub trait TenoriteService<Request, Response, Error, Task, TaskConfig, TaskResult>
where
Request: Send + Debug + 'static,
Response: Send + Debug + 'static,
Error: Send + Debug + 'static,
Task: TenoriteWorker<Request, Response, Error, TaskConfig>,
Task: TenoriteWorker<Request, Response, Error, TaskConfig, TaskResult>,
TaskConfig: Send + 'static,
TaskResult: Send + 'static
{
/// Begins the task thread with the given configuration, returns the task
/// and a client handle for communicating with the server
fn start_task(
&self,
backlog_size: usize,
config: TaskConfig,
) -> (JoinHandle<()>, TenoriteCaller<Request, Response, Error>) {
) -> (JoinHandle<TaskResult>, TenoriteCaller<Request, Response, Error>) {
let (sender, receiver) = mpsc::channel(backlog_size);
let task = tokio::spawn(async move {
<Task as TenoriteWorker<Request, Response, Error, TaskConfig>>::task(receiver, config)
<Task as TenoriteWorker<Request, Response, Error, TaskConfig, TaskResult>>::task(receiver, config)
.await
});
(
Expand Down
4 changes: 2 additions & 2 deletions src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::request::TenoriteRequest;
/// This trait specifies the worker end of the service. the `task()` method is
/// what implements the server side logic.
#[async_trait]
pub trait TenoriteWorker<Request, Response, Error, TaskConfig>
pub trait TenoriteWorker<Request, Response, Error, TaskConfig, TaskResult>
where Request: Debug,
Response: Debug,
Error: Debug,
Expand All @@ -16,5 +16,5 @@ pub trait TenoriteWorker<Request, Response, Error, TaskConfig>
async fn task(
mut receiver: Receiver<TenoriteRequest<Request, Response, Error>>,
config: TaskConfig,
);
) -> TaskResult;
}

0 comments on commit 79a1d4a

Please sign in to comment.