feat(client): await managed updates from blocking callers
This commit is contained in:
1 parent
344533f8b6
commit
31fd76f78d
2 files changed
+17
-8
No files matched your search
@@ -250,15 +250,11 @@ fn dynamic_update_reaches_background_worker() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
let handle = owner.handle();
|
let handle = owner.handle();
|
||||||
|
|
||||||
let acknowledgement = test_runtime().block_on(async {
|
let acknowledgement = handle
|
||||||
timeout(
|
.update_targets(vec![target(&server)])
|
||||||
Duration::from_secs(2),
|
|
||||||
handle.update_targets(vec![target(&server)]).unwrap(),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.unwrap()
|
.blocking_wait()
|
||||||
});
|
.unwrap();
|
||||||
assert_eq!(acknowledgement.sequence, 1);
|
assert_eq!(acknowledgement.sequence, 1);
|
||||||
server.wait_probe();
|
server.wait_probe();
|
||||||
test_runtime().block_on(async {
|
test_runtime().block_on(async {
|
||||||
|
|||||||
@@ -301,6 +301,19 @@ pub struct ManagedCommandReceipt {
|
|||||||
receiver: oneshot::Receiver<Result<ManagedCommandAcknowledgement, ManagedCommandApplyError>>,
|
receiver: oneshot::Receiver<Result<ManagedCommandAcknowledgement, ManagedCommandApplyError>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl ManagedCommandReceipt {
|
||||||
|
/// Block until the target-set transaction is applied or rejected.
|
||||||
|
///
|
||||||
|
/// This is for synchronous callers such as [`BlockingManagedClient`]. It
|
||||||
|
/// must not be called from an asynchronous runtime; use the [`Future`]
|
||||||
|
/// implementation there instead.
|
||||||
|
pub fn blocking_wait(self) -> Result<ManagedCommandAcknowledgement, ManagedCommandApplyError> {
|
||||||
|
self.receiver
|
||||||
|
.blocking_recv()
|
||||||
|
.unwrap_or(Err(ManagedCommandApplyError::AcknowledgementDisconnected))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Future for ManagedCommandReceipt {
|
impl Future for ManagedCommandReceipt {
|
||||||
type Output = Result<ManagedCommandAcknowledgement, ManagedCommandApplyError>;
|
type Output = Result<ManagedCommandAcknowledgement, ManagedCommandApplyError>;
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
|
|||||||
Reference in new issue
Block a user