Skip to content

Commit b7ef253

Browse files
docs: Minor docs fixes (#674)
1 parent 9661b10 commit b7ef253

File tree

5 files changed

+66
-9
lines changed

5 files changed

+66
-9
lines changed

TROUBLESHOOTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ failed to select a version for `ic-cdk-executor` which could resolve this confli
1919

2020
You have two incompatible versions of `ic-cdk` in your dependency tree. There are two common reasons for this.
2121

22-
First, a dependency may be using an older (or newer) version of the CDK. Many versions are compatible with each other, but versions 0.17 and earlier are incompatible with versions 0.18 or later. You will have to wait for those dependencies to update, or patch them yourself.
22+
First, a dependency may be using an older (or newer) version of the CDK. Many versions are compatible with each other, but versions 0.17 and earlier are incompatible with version 0.18, and 0.18 is incompatible with 0.19 or later. You will have to wait for those dependencies to update, or patch them yourself.
2323

2424
Second, a dependency may be using a nominally compatible version of the CDK, but you are using a GitHub prerelease of the CDK with `ic-cdk = { git =`. Git dependencies are automatically incompatible with everything, even if nothing changed. You will need to create a [patch table](https://doc.rust-lang.org/cargo/reference/overriding-dependencies.html) that replaces `ic-cdk` with a Git dependency at the same commit (you may also need to replace `ic-cdk-executor`).
2525

ic-cdk-executor/README.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# `ic-cdk-executor`
2+
3+
An async executor for [`ic-cdk`](https://docs.rs/ic-cdk). Most users should not use this crate directly. It is useful primarily for those who are writing their own CDK or a runtime host for non-Rust languages.
4+
5+
## Contexts
6+
7+
The expected boilerplate for a canister method or other entrypoint (*not* including callbacks) looks like this:
8+
9+
```rust
10+
pub extern "C" fn function() {
11+
in_tracking_executor_context(|| {
12+
// method goes here
13+
});
14+
}
15+
```
16+
17+
The `in_tracking_executor_context` function permits you to call `spawn_*` functions. As little code as possible
18+
should exist outside the block, because `in_tracking_executor_context` additionally sets up the panic handler.
19+
20+
The above applies to update contexts. Query contexts, including `inspect_message`, should use
21+
`in_tracking_query_executor_context`.
22+
23+
The expected boilerplate for an inter-canister call callback looks like this:
24+
25+
```rust
26+
unsafe extern "C" fn callback(env: usize) {
27+
let method = unpack_env(env);
28+
in_callback_executor_context_for(method, || {
29+
// wake the call future
30+
});
31+
}
32+
unsafe extern "C" fn cleanup(env: usize) {
33+
let method = unpack_env(env);
34+
in_trap_recovery_context_for(method, || {
35+
cancel_all_tasks_attached_to_current_method();
36+
});
37+
}
38+
```
39+
40+
In async contexts, all scheduled tasks are run *after* the closure passed to the context function
41+
returns, but *before* the context function itself returns.
42+
43+
The `method` parameter must be retrieved *before* making inter-canister calls via the `extend_current_method_context`
44+
function. Calling this function from the callback instead will trap.
45+
46+
## Protection
47+
48+
Tasks can be either *protected* or *migratory*. Protected tasks are attached to the method that spawned them,
49+
when awoken will not resume until that method continues, and will be canceled if the method returns before they complete.
50+
Migratory tasks are not attached to any method, and will resume in whatever method wakes them.

ic-cdk-executor/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
//! }
1515
//! ```
1616
//!
17-
//! The `in_tracking_executor_context` function permits you to call `spawn_*` functions. As little code as possible
18-
//! should exist outside the block, because `in_tracking_executor_context` additionally sets up the panic handler.
17+
//! The [`in_tracking_executor_context`] function permits you to call `spawn_*` functions. As little code as possible
18+
//! should exist outside the block, because [`in_tracking_executor_context`] additionally sets up the panic handler.
1919
//!
20-
//! The above applies to update contexts. Query contexts, including `inspect_message`, should use
21-
//! `in_tracking_query_executor_context`.
20+
//! The above applies to update contexts. Query contexts, including `canister_inspect_message`, should use
21+
//! [`in_tracking_query_executor_context`].
2222
//!
2323
//! The expected boilerplate for an inter-canister call callback looks like this:
2424
//!

ic-cdk-executor/src/machinery.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl Default for Task {
9393
}
9494
}
9595

96-
/// Execute an update function in a context that allows calling [`spawn_protected`] and [`spawn_migratory`]
96+
/// Execute an update function in a context that allows calling [`spawn_protected`] and [`spawn_migratory`].
9797
pub fn in_tracking_executor_context<R>(f: impl FnOnce() -> R) -> R {
9898
setup_panic_hook();
9999
let method = METHODS.with_borrow_mut(|methods| methods.insert(MethodContext::new_update()));
@@ -143,7 +143,7 @@ pub fn in_callback_executor_context_for<R>(
143143
})
144144
}
145145

146-
/// Enters a panic recovery context for calling [`cancel_all_tasks_attached_to_current_method`] in.
146+
/// Enters a trap/panic recovery context for calling [`cancel_all_tasks_attached_to_current_method`] in.
147147
pub fn in_trap_recovery_context_for<R>(method: MethodHandle, f: impl FnOnce() -> R) -> R {
148148
setup_panic_hook();
149149
enter_current_method(method, || {
@@ -398,8 +398,8 @@ pub fn spawn_migratory(f: impl Future<Output = ()> + 'static) -> TaskHandle {
398398

399399
/// Spawns a task attached to the current method.
400400
///
401-
/// When the task is awoken, if a different method is currently running, it will not run until the method
402-
/// it is attached to continues. If the attached method returns before the task completes, it will be canceled.
401+
/// When the task is awoken, if a different method is currently running, the task will not run until the method
402+
/// it is attached to continues. If the attached method returns before the task completes, the task will be canceled.
403403
pub fn spawn_protected(f: impl Future<Output = ()> + 'static) -> TaskHandle {
404404
setup_panic_hook();
405405
if is_recovering_from_trap() {

ic-cdk-timers/src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,13 @@ pub fn set_timer(delay: Duration, future: impl Future<Output = ()> + 'static) ->
362362
///
363363
/// Note that timers are not persisted across canister upgrades.
364364
///
365+
/// <div class="warning">
366+
///
367+
/// Interval timers should be *idempotent* with respect to the canister's state, as during heavy network load,
368+
/// timeouts may result in duplicate execution.
369+
///
370+
/// </div>
371+
///
365372
/// # Examples
366373
///
367374
/// ```no_run

0 commit comments

Comments
 (0)