Rust

adapter

Module

Adapters: how a CLI application's work is run.

Contents

use utopia_cli::Generic;
Rust
pub struct Generic

Runs the work once, in the calling task: worker callbacks are ignored and Adapter::on_job runs the job at once.

Rust
use utopia_cli::{Adapter, Generic};

let adapter = Generic::new();
assert_eq!(adapter.workers(), 0);
let mut ran = false;
adapter.on_job(&mut || ran = true);
assert!(ran);
use utopia_cli::Workers;
Rust
pub struct Workers

Runs the work in n concurrent workers (at least one), each calling its worker-start callbacks, the job, then its worker-stop callbacks.

Rust
use std::sync::atomic::{AtomicUsize, Ordering};
use utopia_cli::{Adapter, Workers};

let runs = AtomicUsize::new(0);
let adapter = Workers::new(3);
adapter.start(&|_worker| Box::pin(async { runs.fetch_add(1, Ordering::SeqCst); })).await;
assert_eq!(runs.load(Ordering::SeqCst), 3);
Also implements Debug.
use utopia_cli::Adapter;
Rust
pub trait Adapter: Send + Sync

Runs a CLI application's work: once in the calling task, or in several workers.

Implemented byGenericWorkers
Rust
pub type Job<'a> = &'a (dyn Fn(usize) -> BoxFuture<'a, ()> + Send + Sync)

The work an adapter runs: called with the worker's number (0 for the only one).

Rust
pub type WorkerCallback = Arc<dyn Fn(usize) + Send + Sync>

A callback an adapter calls with a worker's number.