From c4ff00dec152caa8e3982d4df5884bd5eb3924c9 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Sat, 6 Dec 2025 15:36:58 -0500 Subject: [PATCH] core: Handle the async process start from the C websocket. --- src/httpd.app.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/httpd.app.c b/src/httpd.app.c index d9a6cbc3..17c064ff 100644 --- a/src/httpd.app.c +++ b/src/httpd.app.c @@ -288,6 +288,15 @@ static void _http_json_send(tf_http_request_t* request, JSContext* context, JSVa JS_FreeValue(context, json); } +static JSValue _httpd_app_on_process_start(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv, int magic, JSValue* func_data) +{ + JSClassID class_id = 0; + app_t* app = JS_GetAnyOpaque(func_data[0], &class_id); + app->process = JS_DupValue(context, argv[0]); + tf_printf("ON START %p => %s\n", app, app->request->path); + return JS_UNDEFINED; +} + static void _httpd_app_hello_after_work(tf_ssb_t* ssb, int status, void* user_data) { app_hello_t* work = user_data; @@ -379,6 +388,23 @@ static void _httpd_app_hello_after_work(tf_ssb_t* ssb, int status, void* user_da }; JSValue result = JS_Call(context, get_process_blob, JS_UNDEFINED, tf_countof(args), args); tf_util_report_error(context, result); + + JSValue promise_then = JS_GetPropertyStr(context, result, "then"); + + JSValue data = JS_NewObject(context); + JS_SetOpaque(data, work->app); + JSValue then = JS_NewCFunctionData(context, _httpd_app_on_process_start, 0, 0, 1, &data); + + JSValue promise = JS_Call(context, promise_then, result, 1, &then); + tf_util_report_error(context, promise); + JS_FreeValue(context, promise); + + /* except? */ + + JS_FreeValue(context, data); + JS_FreeValue(context, then); + JS_FreeValue(context, promise_then); + JS_FreeValue(context, result); JS_FreeValue(context, get_process_blob); @@ -517,6 +543,8 @@ static void _httpd_app_on_close(tf_http_request_t* request) app_t* work = request->user_data; JS_FreeValue(context, work->credentials); _httpd_app_kill_task(work); + JS_FreeValue(context, work->process); + work->process = JS_UNDEFINED; tf_free(work); tf_http_request_unref(request);