Skip to content

Commit

Permalink
change azle reject and resolve ids to a better name
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Jan 4, 2025
1 parent cbe3768 commit f9b0d46
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 18 deletions.
Binary file modified canister_templates/experimental.wasm
Binary file not shown.
Binary file modified canister_templates/stable.wasm
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ impl JsFn for NativeFunction {
let reject_id = format!("_reject_{}", promise_id);
let resolve_id = format!("_resolve_{}", promise_id);

let reject_ids = global.get("_azleRejectIds");
let resolve_ids = global.get("_azleResolveIds");
let reject_callbacks = global.get("_azleRejectCallbacks");
let resolve_callbacks = global.get("_azleResolveCallbacks");

reject_ids.to_obj().unwrap().delete(&reject_id);
resolve_ids.to_obj().unwrap().delete(&resolve_id);
reject_callbacks.to_obj().unwrap().delete(&reject_id);
resolve_callbacks.to_obj().unwrap().delete(&resolve_id);
});

let call_result =
Expand Down Expand Up @@ -89,7 +89,7 @@ impl JsFn for NativeFunction {

if should_resolve {
let resolve = global
.get("_azleResolveIds")
.get("_azleResolveCallbacks")
.to_obj()
.unwrap()
.get(format!("_resolve_{promise_id}").as_str())
Expand All @@ -111,7 +111,7 @@ impl JsFn for NativeFunction {
};
} else {
let reject = global
.get("_azleRejectIds")
.get("_azleRejectCallbacks")
.to_obj()
.unwrap()
.get(format!("_reject_{promise_id}").as_str())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ fn cleanup(ctx: Ctx, promise_id: &str) -> Result<(), Box<dyn Error>> {

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

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

reject_ids.remove(&reject_id)?;
resolve_ids.remove(&resolve_id)?;
Expand Down Expand Up @@ -147,9 +147,9 @@ fn get_resolve_or_reject_global_object(
let globals = ctx.globals();

if should_resolve {
Ok(globals.get("_azleResolveIds")?)
Ok(globals.get("_azleResolveCallbacks")?)
} else {
Ok(globals.get("_azleRejectIds")?)
Ok(globals.get("_azleRejectCallbacks")?)
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/lib/experimental/ic/call_raw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ export function callRaw(
const globalResolveId = `_resolve_${promiseId}`;
const globalRejectId = `_reject_${promiseId}`;

globalThis._azleResolveIds[globalResolveId] = (
globalThis._azleResolveCallbacks[globalResolveId] = (
bytes: ArrayBuffer
): void => {
resolve(new Uint8Array(bytes));
};

globalThis._azleRejectIds[globalRejectId] = (error: any): void => {
globalThis._azleRejectCallbacks[globalRejectId] = (
error: any
): void => {
reject(error);
};

Expand Down
10 changes: 6 additions & 4 deletions src/lib/stable/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ declare global {
// eslint-disable-next-line no-var
var _azleRecordBenchmarks: boolean;
// eslint-disable-next-line no-var
var _azleRejectIds: { [key: string]: (err: any) => void };
var _azleRejectCallbacks: { [key: string]: (err: any) => void };
// eslint-disable-next-line no-var
var _azleResolveIds: { [key: string]: (buf: Uint8Array) => void };
var _azleResolveCallbacks: {
[key: string]: (buf: Uint8Array | ArrayBuffer) => void;
};
// eslint-disable-next-line no-var
var _azleTimerCallbacks: { [key: string]: () => void };
}
Expand All @@ -54,9 +56,9 @@ if (globalThis._azleInsideCanister === true) {

globalThis._azleIcTimers = {};

globalThis._azleRejectIds = {};
globalThis._azleRejectCallbacks = {};

globalThis._azleResolveIds = {};
globalThis._azleResolveCallbacks = {};

globalThis.TextDecoder = TextDecoder;
globalThis.TextEncoder = TextEncoder;
Expand Down
6 changes: 4 additions & 2 deletions src/lib/stable/ic_apis/call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function call<Args extends any[] | undefined, Return = any>(
const returnTypeIdl = options?.returnIdlType;
const raw = options?.raw;

globalThis._azleResolveIds[globalResolveId] = (
globalThis._azleResolveCallbacks[globalResolveId] = (
result: Uint8Array | ArrayBuffer
): void => {
if (raw !== undefined) {
Expand All @@ -45,7 +45,9 @@ export async function call<Args extends any[] | undefined, Return = any>(
}
};

globalThis._azleRejectIds[globalRejectId] = (error: any): void => {
globalThis._azleRejectCallbacks[globalRejectId] = (
error: any
): void => {
reject(error);
};

Expand Down

0 comments on commit f9b0d46

Please sign in to comment.