I ran an async function and printed the logs, but the logs were not in the correct sequence.
// pseudo code
pub async fn execute (id:u32) -> () {
Self::repay(id, insurance.insurance_asset.clone()).await;
print("None of the buyers participated".to_owned());
}
/// Repay the amount to Insurance Contract Sellers
async fn repay(insurance_id: u32,insurance_asset: InsuranceAssets) -> () {
print("Repay to Sellers Start");
print("Ledger Initialization Start");
///Code...
print("Ledger Initialization End");
mutate_state(|s| {
s.stable_state
.insurance_sellers
.iter()
.filter(|(key, _)| key.insurance_id == insurance_id)
.for_each(|(k, v)| {
ic_cdk::println!("Insurance Asset Fee {:?}", insurance_asset_fee);
spawn(async move {
let transfer_res: transfer().await;
match transfer_res {
TransferSuccess(_) => {
Self::remove_seller_from_insurance_sellers_list(&key);
ic_cdk::print("Tranfer Success");
}}
})
})
}
/// NOTE : Since there are two entries in a vec
> Output :
Repay to Sellers Start
Ledger Initialization Start
Ledger Initialization End
Insurance Asset Fee Nat(10000)
Insurance Asset Fee Nat(10000)
None of the buyers participated
Tranfer Success
Tranfer Success
> Expected Output :
Repay to Sellers Start
Ledger Initialization Start
Ledger Initialization End
Insurance Asset Fee Nat(10000)
Tranfer Success
Insurance Asset Fee Nat(10000)
Tranfer Success
None of the buyers participated