Skip to content

Commit

Permalink
fixed unwraps
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Dec 12, 2024
1 parent 2f8085f commit 65000e4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
Binary file modified canister_templates/stable.wasm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,11 @@ pub fn get_function(ctx: Ctx) -> QuickJsResult<Function> {
// Even during a trap, the IC will ensure that the closure runs in its own call
// thus allowing us to recover from a trap and persist that state
let _cleanup = scopeguard::guard((), |_| {
let reject_id = format!("_reject_{}", &promise_id);
let resolve_id = format!("_resolve_{}", &promise_id);
let result = cleanup(ctx.clone(), &promise_id);

let globals = ctx.clone().globals();

let reject_ids = globals.get::<_, Object>("_azleRejectIds").unwrap();
let resolve_ids = globals.get::<_, Object>("_azleResolveIds").unwrap();

reject_ids.remove(&reject_id).unwrap();
resolve_ids.remove(&resolve_id).unwrap();
if let Err(e) = result {
trap(&format!("Azle CallRawCleanupError: {e}"));
}
});

let call_result = call_raw128(canister_id, &method, args_raw, payment).await;
Expand All @@ -83,6 +78,21 @@ pub fn get_function(ctx: Ctx) -> QuickJsResult<Function> {
)
}

fn cleanup(ctx: Ctx, promise_id: &str) -> Result<(), Box<dyn Error>> {
let reject_id = format!("_reject_{}", promise_id);
let resolve_id = format!("_resolve_{}", promise_id);

let globals = ctx.clone().globals();

let reject_ids = globals.get::<_, Object>("_azleRejectIds")?;
let resolve_ids = globals.get::<_, Object>("_azleResolveIds")?;

reject_ids.remove(&reject_id)?;
resolve_ids.remove(&resolve_id)?;

Ok(())
}

fn resolve_or_reject<'a>(
ctx: Ctx<'a>,
call_result: &Result<Vec<u8>, (RejectionCode, String)>,
Expand Down

0 comments on commit 65000e4

Please sign in to comment.