Hi folks, a set of beta releases for ic-cdk 0.19 are now available:
ic-cdk = "0.19.0-beta.3"
ic-cdk-timers = "1.0.0-beta.1"
Async/await
The most consequential change is the new async executor. The 0.18 executor introduced new capabilities, and one of them is a footgun: the ability for a task to suspend during one canister method and resume during another. In 0.19 this is prevented: a task will only resume during the method that spawned it, and if the method ends before the task has completed, it will panic.
New related functions are also added: spawn_weak will spawn tasks that cancel when they outlast the canister method, and spawn_migratory opts into the ability to outlast the canister method, keeping the behavior from 0.18. In the future we intend to forbid spawn_migratory tasks from calling functions beginning with msg_*, which are the primary footgun.
If you are using inter-canister calls in conventional ways (including composing them with futuresâ FuturesUnordered and other abstractions around futures) this should not affect you. If it does affect you, please report it as a bug. It should only affect complex use cases involving channels or other similar manually-triggered futures. It should in particular not be possible for this to affect any code that worked in 0.17.
Canister environment variables
This release supports the canister side of the new canister environment variables API. Canister environment variables are a key-value map that can be read and written by the canister and by external tools. You can use these for any kind of controller-updatable settings that you donât want to go to the effort of building an API and storage mechanism into your canister for.
We intend eventually to make it easy to use these to store principals for canisters you make inter-canister calls to, instead of baking that information into the WASM. This will allow bindings generators to not need to talk to dfx, and eliminate the requirement for different builds for local dev and mainnet.
Timers
Timer bodies are now async. You have probably written a lot of timers that looked like this:
set_timer(|| {
spawn(async {
make_call().await;
})
})
Now, this can be shortened to:
set_timer(async {
make_call().await;
})
You might also notice that the new ic-cdk-timers version is 1.0.0 rather than an 0.x release. Going forwards, ic-cdk-timers does not depend on ic-cdk, and will not need to be updated when ic-cdk updates. This will enhance compatibility between libraries using different versions of the CDK.
Please try out these new versions and let us know if you encounter any issues!