Skip to content

Commit

Permalink
patch up setTimeout a bit, run the task queue after method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
lastmjs committed Jan 15, 2024
1 parent b5f36eb commit 175bad1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/compiler/rust/canister/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ fn execute_js(function_name: &str, pass_arg_data: bool) {
// TODO this returns a value so I think we need to check it to get an error
method_callback_function.call(&[candid_args_js_value]);

// TODO might we need to do this in init and post_upgrade?
context.event_loop().unwrap().run_tick_task();

// TODO I am not sure what the first parameter to call is supposed to be
// method_callback
// .call(&method_callback, &[candid_args_js_value_ref])
Expand Down
11 changes: 11 additions & 0 deletions src/lib/globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,14 @@ globalThis.crypto = {
};

globalThis.Buffer = Buffer;

const originalSetTimeout = setTimeout;

(globalThis as any).setTimeout = (handler: TimerHandler, timeout?: number) => {
if (timeout === undefined || timeout === 0) {
return originalSetTimeout(handler, 0);
}

// TODO change this to throw once errors throw and show up properly
ic.trap(`setTimeout cannot be called with milliseconds above 0`);
};

0 comments on commit 175bad1

Please sign in to comment.