✨ pending collector iterators
This commit is contained in:
parent
00e448ac31
commit
b043db3f4e
4 changed files with 176 additions and 7 deletions
|
@ -13,6 +13,9 @@ use syn::{FnArg, Ident, ItemFn, Pat, ReturnType, Type, parse_macro_input};
|
|||
/// - `fn_init_union_scoped(ServiceManager) -> ServiceManager` - Register worker threads and work in a union using Valkey and return a scoped struct.
|
||||
/// - `fn_register_union()` - Register the worker in a union setup without starting local worker threads.
|
||||
///
|
||||
/// # Notes
|
||||
/// Keep in mind that `return` statements are not allowed in a worker function. The return values must be explicitly at the end of the function as an expression.
|
||||
///
|
||||
/// # Examples
|
||||
/// ```ignore
|
||||
/// use comrade::worker;
|
||||
|
@ -128,7 +131,7 @@ pub fn worker(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||
}
|
||||
}
|
||||
|
||||
fn #wrapper_fn(task: JobOrder<comrade::serde_json::Value, comrade::serde_json::Value>) {
|
||||
fn #wrapper_fn(task: comrade::job::JobOrder<comrade::serde_json::Value, comrade::serde_json::Value>) {
|
||||
let i = task.param.clone();
|
||||
|
||||
// Deserialize the parameter into the function's expected types
|
||||
|
@ -173,14 +176,14 @@ pub fn worker(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||
}
|
||||
|
||||
#[doc = "Initialize a worker thread on `ServiceManager`"]
|
||||
pub fn #init_fn(sm: ServiceManager) -> ServiceManager {
|
||||
pub fn #init_fn(sm: comrade::service::ServiceManager) -> comrade::service::ServiceManager {
|
||||
let mut dispatchers = Vec::new();
|
||||
let mut s = sm;
|
||||
|
||||
log::info!("Initializing worker {} with {} threads", stringify!(#worker_fn), #worker_count);
|
||||
|
||||
for i in 0..#worker_count {
|
||||
let (dispatch, recv): (JobDispatcher<_, _>, Receiver<JobOrder<_, _>>) = JobDispatcher::new();
|
||||
let (dispatch, recv): (comrade::job::JobDispatcher<_, _>, comrade::crossbeam::channel::Receiver<comrade::job::JobOrder<_, _>>) = comrade::job::JobDispatcher::new();
|
||||
|
||||
s = s.register(
|
||||
&format!("{}_{i}", stringify!(#worker_fn)),
|
||||
|
@ -211,7 +214,7 @@ pub fn worker(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||
}
|
||||
|
||||
#[doc = "Initialize worker threads on `ServiceManager` with Valkey backend"]
|
||||
pub fn #init_fn_union(sm: ServiceManager) -> ServiceManager {
|
||||
pub fn #init_fn_union(sm: comrade::service::ServiceManager) -> comrade::service::ServiceManager {
|
||||
let mut dispatchers = Vec::new();
|
||||
let mut s = sm;
|
||||
|
||||
|
@ -254,13 +257,13 @@ pub fn worker(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||
}
|
||||
|
||||
#[doc = "Initialize a worker thread on `ServiceManager` on a scoped lifetime"]
|
||||
pub fn #init_fn_scoped(sm: ServiceManager) -> (ServiceManager, #fn_scope_struct) {
|
||||
pub fn #init_fn_scoped(sm: comrade::service::ServiceManager) -> (comrade::service::ServiceManager, #fn_scope_struct) {
|
||||
let sm = #init_fn(sm);
|
||||
(sm, #fn_scope_struct {})
|
||||
}
|
||||
|
||||
#[doc = "Initialize a worker union on `ServiceManager` on a scoped lifetime"]
|
||||
pub fn #init_fn_scoped_union(sm: ServiceManager) -> (ServiceManager, #fn_scope_struct) {
|
||||
pub fn #init_fn_scoped_union(sm: comrade::service::ServiceManager) -> (comrade::service::ServiceManager, #fn_scope_struct) {
|
||||
let sm = #init_fn_union(sm);
|
||||
(sm, #fn_scope_struct {})
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue