Skip to content

Commit f39b5a6

Browse files
authored
docs: Clarify Call to CallFuture conversion and fix minor inaccuracies (#669)
1 parent 715e3be commit f39b5a6

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

ic-cdk/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ thiserror.workspace = true
4040
[dev-dependencies]
4141
anyhow = "1"
4242
candid_parser.workspace = true
43+
futures = "0.3"
4344
rstest = "0.12.0"
4445
trybuild = "1.0"
4546

ic-cdk/src/api.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ pub fn canister_liquid_cycle_balance() -> u128 {
167167
/// Gets the status of the canister.
168168
///
169169
/// The status is one of the following:
170-
///.- 1: Running
171-
///.- 2: Stopping
172-
///.- 3: Stopped
170+
/// - 1: Running
171+
/// - 2: Stopping
172+
/// - 3: Stopped
173173
pub fn canister_status() -> CanisterStatusCode {
174174
ic0::canister_status().into()
175175
}

ic-cdk/src/call.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,31 @@ pub use ic_error_types::RejectCode;
103103
/// # Execution
104104
///
105105
/// A [`Call`] can be executed in two ways:
106-
/// - `.await`: convert into a future, execute asynchronously and wait for response.
107-
/// - [`oneway`][Self::oneway]: send a oneway call and not wait for the response.
106+
/// - **Asynchronously**: Convert to a [`CallFuture`] and await the response.
107+
/// - Direct approach: Use `.await` on the call (e.g., `call.await`).
108+
/// - Collective approach: Use [`IntoFuture::into_future`] to obtain futures explicitly,
109+
/// then combine them with `join!`, `select!`, or other combinators.
110+
/// - **One-way**: Send a call with [`oneway`][Self::oneway] when you don't need a response.
108111
///
109112
/// ## Example
110113
///
111114
/// ```rust, no_run
112115
/// # use ic_cdk::call::Call;
116+
/// # use candid::Principal;
113117
/// # async fn bar() {
114-
/// # let canister_id = ic_cdk::api::canister_self();
115-
/// # let method = "foo";
116-
/// let call = Call::bounded_wait(canister_id, method);
117-
/// let response = call.clone().await.unwrap();
118-
/// call.oneway().unwrap();
118+
/// # let canister_id : Principal = todo!();
119+
/// # let method: &str = todo!();
120+
/// # let canister_id1 : Principal = todo!();
121+
/// # let method1: &str = todo!();
122+
/// # let canister_id2 : Principal = todo!();
123+
/// # let method2: &str = todo!();
124+
/// let response = Call::bounded_wait(canister_id, method).await;
125+
/// let calls = vec![
126+
/// Call::bounded_wait(canister_id1, method1).into_future(),
127+
/// Call::bounded_wait(canister_id2, method2).into_future(),
128+
/// ];
129+
/// let responses = futures::future::join_all(calls).await;
130+
/// Call::bounded_wait(canister_id, method).oneway().unwrap();
119131
/// # }
120132
/// ```
121133
///

ic-cdk/src/management_canister.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ pub fn cost_http_request(arg: &HttpRequestArgs) -> u128 {
521521
ic0_cost_http_request(request_size, max_res_bytes)
522522
}
523523

524-
/// Makes an HTTP outcall with a user-specified amount of cycles.
524+
/// Makes an HTTP outcall.
525525
///
526526
/// **Unbounded-wait call**
527527
///

0 commit comments

Comments
 (0)