pub struct ManualWorker { /* private fields */ }Expand description
Manual single-step worker for tests (no background task).
Use BosonBuilder::build_manual to obtain one alongside
Boson. Call try_run_next to claim and execute at most
one queued job — useful in unit tests and the task_macro example.
§Example
use std::sync::Arc;
use boson_backend_mem::MemQueueBackend;
use boson_core::{ExecutionContext, JsonExecutionContextFactory};
use boson_macros::task;
use boson_runtime::{configure, Boson, ManualWorker};
#[task(name = "ping")]
async fn ping(_ctx: Box<dyn ExecutionContext>) -> boson_core::Result<()> {
Ok(())
}
let (boson, manual) = Boson::builder()
.queue_backend(Arc::new(MemQueueBackend::new()))
.execution_context_factory(JsonExecutionContextFactory)
.auto_registry()
.build_manual()?;
configure(boson);
Ping::send_with(serde_json::json!({"System": {}}), PingParams {}).await?;
assert!(manual.try_run_next().await); // runs the handler onceImplementations§
Source§impl ManualWorker
impl ManualWorker
Sourcepub fn new(
backend: Arc<dyn QueueBackend>,
registry: Arc<TaskRegistry>,
identity: Arc<dyn ExecutionContextFactory>,
worker: WorkerSettings,
) -> ManualWorker
pub fn new( backend: Arc<dyn QueueBackend>, registry: Arc<TaskRegistry>, identity: Arc<dyn ExecutionContextFactory>, worker: WorkerSettings, ) -> ManualWorker
Create a worker that can be driven step-by-step in tests.
Sourcepub async fn try_run_next(&self) -> bool
pub async fn try_run_next(&self) -> bool
Process at most one job across all pools.
Auto Trait Implementations§
impl !Freeze for ManualWorker
impl !RefUnwindSafe for ManualWorker
impl !UnwindSafe for ManualWorker
impl Send for ManualWorker
impl Sync for ManualWorker
impl Unpin for ManualWorker
impl UnsafeUnpin for ManualWorker
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more