Skip to content

Commit 608a3f4

Browse files
feat!: SyncCall/AsyncCall enhancements (#539)
1 parent 1a16e17 commit 608a3f4

File tree

11 files changed

+335
-158
lines changed

11 files changed

+335
-158
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## Unreleased
1010

11+
* Changed the SyncCall and AsyncCall traits to use an associated type for their output instead of a generic parameter.
12+
* Call builders now generally implement `IntoFuture`, allowing `.call_and_wait().await` to be shortened to `.await`.
13+
1114
## [0.35.0] - 2024-05-10
1215

1316
* Added a limit to the concurrent requests an agent will make at once. This should make server-side ratelimiting much rarer to encounter, even when sending a high volume of requests (for example, a large `ic_utils::ManagementCanister::install` call).

ic-agent/src/agent/mod.rs

+17-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use std::{
4848
collections::HashMap,
4949
convert::TryFrom,
5050
fmt,
51-
future::Future,
51+
future::{Future, IntoFuture},
5252
pin::Pin,
5353
sync::{Arc, Mutex, RwLock},
5454
task::{Context, Poll},
@@ -234,7 +234,6 @@ pub enum PollResult {
234234
/// let response = agent.update(&management_canister_id, "provisional_create_canister_with_cycles")
235235
/// .with_effective_canister_id(effective_canister_id)
236236
/// .with_arg(Encode!(&Argument { amount: None })?)
237-
/// .call_and_wait()
238237
/// .await?;
239238
///
240239
/// let result = Decode!(response.as_slice(), CreateCanisterResult)?;
@@ -1614,6 +1613,14 @@ impl<'agent> QueryBuilder<'agent> {
16141613
}
16151614
}
16161615

1616+
impl<'agent> IntoFuture for QueryBuilder<'agent> {
1617+
type IntoFuture = AgentFuture<'agent, Vec<u8>>;
1618+
type Output = Result<Vec<u8>, AgentError>;
1619+
fn into_future(self) -> Self::IntoFuture {
1620+
Box::pin(self.call())
1621+
}
1622+
}
1623+
16171624
/// An in-flight canister update call. Useful primarily as a `Future`.
16181625
pub struct UpdateCall<'agent> {
16191626
agent: &'agent Agent,
@@ -1769,6 +1776,14 @@ impl<'agent> UpdateBuilder<'agent> {
17691776
}
17701777
}
17711778

1779+
impl<'agent> IntoFuture for UpdateBuilder<'agent> {
1780+
type IntoFuture = AgentFuture<'agent, Vec<u8>>;
1781+
type Output = Result<Vec<u8>, AgentError>;
1782+
fn into_future(self) -> Self::IntoFuture {
1783+
Box::pin(self.call_and_wait())
1784+
}
1785+
}
1786+
17721787
#[cfg(all(test, feature = "reqwest", not(target_family = "wasm")))]
17731788
mod offline_tests {
17741789
use super::*;

ic-agent/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
//! let response = agent.update(&management_canister_id, "provisional_create_canister_with_cycles")
7474
//! .with_effective_canister_id(effective_canister_id)
7575
//! .with_arg(Encode!(&Argument { amount: None})?)
76-
//! .call_and_wait()
7776
//! .await?;
7877
//!
7978
//! let result = Decode!(response.as_slice(), CreateCanisterResult)?;

0 commit comments

Comments
 (0)