mirror of
https://github.com/openai/codex.git
synced 2026-05-04 21:32:21 +03:00
Add setTimeout support to code mode (#16153)
The implementation is less than ideal - it starts a thread per timer. A better approach might be to switch to tokio and use their timer imlementation.
This commit is contained in:
@@ -3,6 +3,7 @@ use crate::response::FunctionCallOutputContentItem;
|
||||
use super::EXIT_SENTINEL;
|
||||
use super::RuntimeEvent;
|
||||
use super::RuntimeState;
|
||||
use super::timers;
|
||||
use super::value::json_to_v8;
|
||||
use super::value::normalize_output_image;
|
||||
use super::value::serialize_output_text;
|
||||
@@ -185,6 +186,35 @@ pub(super) fn notify_callback(
|
||||
retval.set(v8::undefined(scope).into());
|
||||
}
|
||||
|
||||
pub(super) fn set_timeout_callback(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
args: v8::FunctionCallbackArguments,
|
||||
mut retval: v8::ReturnValue<v8::Value>,
|
||||
) {
|
||||
let timeout_id = match timers::schedule_timeout(scope, args) {
|
||||
Ok(timeout_id) => timeout_id,
|
||||
Err(error_text) => {
|
||||
throw_type_error(scope, &error_text);
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
retval.set(v8::Number::new(scope, timeout_id as f64).into());
|
||||
}
|
||||
|
||||
pub(super) fn clear_timeout_callback(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
args: v8::FunctionCallbackArguments,
|
||||
mut retval: v8::ReturnValue<v8::Value>,
|
||||
) {
|
||||
if let Err(error_text) = timers::clear_timeout(scope, args) {
|
||||
throw_type_error(scope, &error_text);
|
||||
return;
|
||||
}
|
||||
|
||||
retval.set(v8::undefined(scope).into());
|
||||
}
|
||||
|
||||
pub(super) fn yield_control_callback(
|
||||
scope: &mut v8::PinScope<'_, '_>,
|
||||
_args: v8::FunctionCallbackArguments,
|
||||
|
||||
Reference in New Issue
Block a user