Skip to content

Commit

Permalink
add promise and tick polling and progressing everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Jan 17, 2024
1 parent 0b28751 commit 1d8c04a
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/compiler/rust/canister/src/ic/call_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ impl JsFn for NativeFunction {
reject.call(&[js_value.clone()]);
}

// TODO do we need to progress setTimeouts and stuff?
// TODO make sure to test this
// context.event_loop().unwrap().run_tick_task();
// TODO Is this all we need to do for promises and timeouts?
context.event_loop().unwrap().run_tick_task();
context.promise_loop_poll();
});
});
Expand Down
5 changes: 2 additions & 3 deletions src/compiler/rust/canister/src/ic/call_raw128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ impl JsFn for NativeFunction {
reject.call(&[js_value.clone()]);
}

// TODO do we need to progress setTimeouts and stuff?
// TODO make sure to test this
// context.event_loop().unwrap().run_tick_task();
// TODO Is this all we need to do for promises and timeouts?
context.event_loop().unwrap().run_tick_task();
context.promise_loop_poll();
});
});
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/rust/canister/src/ic/set_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ impl JsFn for NativeFunction {

timer_callback.call(&[]);

// TODO Is this all we need to do for promises and timeouts?
context.event_loop().unwrap().run_tick_task();
context.promise_loop_poll();

// TODO handle errors
});
});
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/rust/canister/src/ic/set_timer_interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ impl JsFn for NativeFunction {

timer_callback.call(&[]);

// TODO Is this all we need to do for promises and timeouts?
context.event_loop().unwrap().run_tick_task();
context.promise_loop_poll();

// TODO handle errors
});
});
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/rust/canister/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ fn execute_js(function_name: &str, pass_arg_data: bool) {
_ => {}
};

// TODO might we need to do this in init and post_upgrade?
// TODO Is this all we need to do for promises and timeouts?
context.event_loop().unwrap().run_tick_task();
context.promise_loop_poll();
});
});
}
Expand Down
10 changes: 10 additions & 0 deletions src/compiler/rust/canister_methods/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ pub fn canister_methods(_: TokenStream) -> TokenStream {

context.eval_global_str("globalThis.exports = {};".to_string());
context.eval_module_str(std::str::from_utf8(MAIN_JS).unwrap().to_string(), "azle_main");

// TODO Is this all we need to do for promises and timeouts?
context.event_loop().unwrap().run_tick_task();
context.promise_loop_poll();

// let temp = context.eval_module_str(std::str::from_utf8(MAIN_JS).unwrap().to_string(), "azle_main");

// match &temp {
Expand Down Expand Up @@ -109,6 +114,11 @@ pub fn canister_methods(_: TokenStream) -> TokenStream {

context.eval_global_str("globalThis.exports = {};".to_string());
context.eval_module_str(std::str::from_utf8(MAIN_JS).unwrap().to_string(), "azle_main");

// TODO Is this all we need to do for promises and timeouts?
context.event_loop().unwrap().run_tick_task();
context.promise_loop_poll();

// let temp = context.eval_module_str(std::str::from_utf8(MAIN_JS).unwrap().to_string(), "azle_main");

// match &temp {
Expand Down

0 comments on commit 1d8c04a

Please sign in to comment.