Skip to main content

BlockingManagedClient

Struct BlockingManagedClient 

Source
pub struct BlockingManagedClient { /* private fields */ }
Expand description

Blocking completion owner for one unified managed Tokio task.

This owner runs exactly one ManagedClient task on one dedicated OS thread with its own current-thread Tokio runtime. Dropping a live owner requests a graceful stop and synchronously joins that worker, so drop may block while bounded managed cleanup completes.

Implementations§

Source§

impl BlockingManagedClient

Source

pub fn start( config: ManagedClientConfig, targets: Vec<ManagedTargetConfig>, ) -> Result<Self, BlockingManagedStartError>

Validate configuration, create a dedicated runtime, and start its worker.

Source

pub fn start_with_subscription( config: ManagedClientConfig, targets: Vec<ManagedTargetConfig>, ) -> Result<(Self, ManagedEventSubscription), BlockingManagedStartError>

Validate configuration, subscribe to presentation events, and start a dedicated managed worker.

The returned subscription exists before the managed task receives its first poll, so it cannot miss startup events because of subscription ordering.

Examples found in repository?
examples/managed_client.rs (line 46)
27fn main() {
28    let config = ManagedClientConfig {
29        client: ClientConfig {
30            open: OpenPolicy {
31                timeouts: vec![Duration::from_millis(300)],
32                ..Default::default()
33            },
34            request: SessionRequest {
35                duration: None,
36                interval: Duration::from_millis(200),
37                ..Default::default()
38            },
39            ..Default::default()
40        },
41        completion: ManagedCompletionPolicy::ExplicitStop,
42        ..Default::default()
43    };
44    let targets = vec![ManagedTargetConfig::new("local", "127.0.0.1:2112")];
45
46    let (owner, mut events) = match BlockingManagedClient::start_with_subscription(config, targets)
47    {
48        Ok(started) => started,
49        Err(err) => {
50            eprintln!("failed to start managed client: {err}");
51            return;
52        }
53    };
54
55    let stop_after = Duration::from_secs(1);
56    let deadline = std::time::Instant::now() + stop_after;
57    while std::time::Instant::now() < deadline {
58        match events.try_recv() {
59            Ok(event) => print_event(&event),
60            Err(_) => std::thread::sleep(Duration::from_millis(50)),
61        }
62    }
63
64    // `stop()` requests the stop synchronously; the returned receipt is only
65    // useful for awaiting durable acknowledgement, which this blocking
66    // example does not need.
67    std::mem::drop(owner.handle().stop());
68    match owner.join() {
69        Ok(outcome) => println!("managed run ended: {:?}", outcome.end_reason),
70        Err(err) => eprintln!("managed worker did not join cleanly: {err}"),
71    }
72}
Source

pub fn handle(&self) -> ManagedClientHandle

Return a cloned managed control and observation capability.

Examples found in repository?
examples/managed_client.rs (line 67)
27fn main() {
28    let config = ManagedClientConfig {
29        client: ClientConfig {
30            open: OpenPolicy {
31                timeouts: vec![Duration::from_millis(300)],
32                ..Default::default()
33            },
34            request: SessionRequest {
35                duration: None,
36                interval: Duration::from_millis(200),
37                ..Default::default()
38            },
39            ..Default::default()
40        },
41        completion: ManagedCompletionPolicy::ExplicitStop,
42        ..Default::default()
43    };
44    let targets = vec![ManagedTargetConfig::new("local", "127.0.0.1:2112")];
45
46    let (owner, mut events) = match BlockingManagedClient::start_with_subscription(config, targets)
47    {
48        Ok(started) => started,
49        Err(err) => {
50            eprintln!("failed to start managed client: {err}");
51            return;
52        }
53    };
54
55    let stop_after = Duration::from_secs(1);
56    let deadline = std::time::Instant::now() + stop_after;
57    while std::time::Instant::now() < deadline {
58        match events.try_recv() {
59            Ok(event) => print_event(&event),
60            Err(_) => std::thread::sleep(Duration::from_millis(50)),
61        }
62    }
63
64    // `stop()` requests the stop synchronously; the returned receipt is only
65    // useful for awaiting durable acknowledgement, which this blocking
66    // example does not need.
67    std::mem::drop(owner.handle().stop());
68    match owner.join() {
69        Ok(outcome) => println!("managed run ended: {:?}", outcome.end_reason),
70        Err(err) => eprintln!("managed worker did not join cleanly: {err}"),
71    }
72}
Source

pub fn join(self) -> Result<ManagedOutcome, BlockingManagedJoinError>

Wait synchronously for the managed task’s authoritative outcome.

Examples found in repository?
examples/managed_client.rs (line 68)
27fn main() {
28    let config = ManagedClientConfig {
29        client: ClientConfig {
30            open: OpenPolicy {
31                timeouts: vec![Duration::from_millis(300)],
32                ..Default::default()
33            },
34            request: SessionRequest {
35                duration: None,
36                interval: Duration::from_millis(200),
37                ..Default::default()
38            },
39            ..Default::default()
40        },
41        completion: ManagedCompletionPolicy::ExplicitStop,
42        ..Default::default()
43    };
44    let targets = vec![ManagedTargetConfig::new("local", "127.0.0.1:2112")];
45
46    let (owner, mut events) = match BlockingManagedClient::start_with_subscription(config, targets)
47    {
48        Ok(started) => started,
49        Err(err) => {
50            eprintln!("failed to start managed client: {err}");
51            return;
52        }
53    };
54
55    let stop_after = Duration::from_secs(1);
56    let deadline = std::time::Instant::now() + stop_after;
57    while std::time::Instant::now() < deadline {
58        match events.try_recv() {
59            Ok(event) => print_event(&event),
60            Err(_) => std::thread::sleep(Duration::from_millis(50)),
61        }
62    }
63
64    // `stop()` requests the stop synchronously; the returned receipt is only
65    // useful for awaiting durable acknowledgement, which this blocking
66    // example does not need.
67    std::mem::drop(owner.handle().stop());
68    match owner.join() {
69        Ok(outcome) => println!("managed run ended: {:?}", outcome.end_reason),
70        Err(err) => eprintln!("managed worker did not join cleanly: {err}"),
71    }
72}

Trait Implementations§

Source§

impl Drop for BlockingManagedClient

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.