From 4d126eb84d00de8f5cac7d8c5632bad71144067c Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Wed, 2 Apr 2025 22:17:52 -0400 Subject: [PATCH] fake async event for dispatcher schedule --- package.json | 12 ++++++------ src/event_js.cpp | 18 ++++++++++++++++++ src/event_js.h | 4 +++- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 23c5cf8..34fa1da 100644 --- a/package.json +++ b/package.json @@ -23,16 +23,16 @@ }, "license": "AGPL-3.0-or-later", "devDependencies": { - "@antfu/eslint-config": "^3.12.1", - "@playwright/test": "^1.50.1", - "@types/node": "^22.13.5", + "@antfu/eslint-config": "^4.11.0", + "@playwright/test": "^1.51.1", + "@types/node": "^22.13.17", "@types/uzip": "^0.20201231.2", "error-stack-parser": "^2.1.4", - "esbuild": "^0.24.2", - "eslint": "^9.17.0", + "esbuild": "^0.25.2", + "eslint": "^9.23.0", "serve": "^14.2.4", "textarea-caret": "^3.1.0", - "typescript": "^5.7.2", + "typescript": "^5.8.2", "uzip": "^0.20201231.0" } } diff --git a/src/event_js.cpp b/src/event_js.cpp index 3943a41..6dac9e9 100644 --- a/src/event_js.cpp +++ b/src/event_js.cpp @@ -29,6 +29,18 @@ struct JSEventSource : public JSEventSourceBase { std::shared_ptr callback_; }; +struct JSEventSourceAsync : public JSEventSourceBase { + JSEventSourceAsync(EventCallback _callback) + : callback_(std::make_shared(std::move(_callback))) {} + + void send() override { + // This is synchronous but probably not a big deal for JS. + (*callback_)(nullptr); + } + + std::shared_ptr callback_; +}; + struct JSEventSourceIO : public JSEventSourceBase { JSEventSourceIO(IOCallback _callback) {} @@ -151,4 +163,10 @@ std::unique_ptr JSEventLoop::addPostEvent(EventCallback callback) { return nullptr; } +std::unique_ptr +JSEventLoop::addAsyncEvent(EventCallback callback) { + auto source = std::make_unique(std::move(callback)); + return source; +} + } // namespace fcitx diff --git a/src/event_js.h b/src/event_js.h index 11d0007..76ccb48 100644 --- a/src/event_js.h +++ b/src/event_js.h @@ -3,7 +3,7 @@ #include namespace fcitx { -class JSEventLoop : public EventLoopInterface { +class JSEventLoop : public EventLoopInterfaceV2 { public: JSEventLoop() = default; ~JSEventLoop() override = default; @@ -20,5 +20,7 @@ class JSEventLoop : public EventLoopInterface { std::unique_ptr addExitEvent(EventCallback callback) override; std::unique_ptr addDeferEvent(EventCallback callback) override; std::unique_ptr addPostEvent(EventCallback callback) override; + std::unique_ptr + addAsyncEvent(EventCallback callback) override; }; } // namespace fcitx