core: Handle the async process start from the C websocket.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 9m5s
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 9m5s
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user