Skip to content

Commit f664ff3

Browse files
authored
fake async event for dispatcher schedule (#26)
1 parent fd0fdd0 commit f664ff3

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@
2323
},
2424
"license": "AGPL-3.0-or-later",
2525
"devDependencies": {
26-
"@antfu/eslint-config": "^3.12.1",
27-
"@playwright/test": "^1.50.1",
28-
"@types/node": "^22.13.5",
26+
"@antfu/eslint-config": "^4.11.0",
27+
"@playwright/test": "^1.51.1",
28+
"@types/node": "^22.13.17",
2929
"@types/uzip": "^0.20201231.2",
3030
"error-stack-parser": "^2.1.4",
31-
"esbuild": "^0.24.2",
32-
"eslint": "^9.17.0",
31+
"esbuild": "^0.25.2",
32+
"eslint": "^9.23.0",
3333
"serve": "^14.2.4",
3434
"textarea-caret": "^3.1.0",
35-
"typescript": "^5.7.2",
35+
"typescript": "^5.8.2",
3636
"uzip": "^0.20201231.0"
3737
}
3838
}

src/event_js.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ struct JSEventSource : public JSEventSourceBase<EventSource> {
2929
std::shared_ptr<EventCallback> callback_;
3030
};
3131

32+
struct JSEventSourceAsync : public JSEventSourceBase<EventSourceAsync> {
33+
JSEventSourceAsync(EventCallback _callback)
34+
: callback_(std::make_shared<EventCallback>(std::move(_callback))) {}
35+
36+
void send() override {
37+
// This is synchronous but probably not a big deal for JS.
38+
(*callback_)(nullptr);
39+
}
40+
41+
std::shared_ptr<EventCallback> callback_;
42+
};
43+
3244
struct JSEventSourceIO : public JSEventSourceBase<EventSourceIO> {
3345
JSEventSourceIO(IOCallback _callback) {}
3446

@@ -151,4 +163,10 @@ std::unique_ptr<EventSource> JSEventLoop::addPostEvent(EventCallback callback) {
151163
return nullptr;
152164
}
153165

166+
std::unique_ptr<EventSourceAsync>
167+
JSEventLoop::addAsyncEvent(EventCallback callback) {
168+
auto source = std::make_unique<JSEventSourceAsync>(std::move(callback));
169+
return source;
170+
}
171+
154172
} // namespace fcitx

src/event_js.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <fcitx-utils/eventloopinterface.h>
44

55
namespace fcitx {
6-
class JSEventLoop : public EventLoopInterface {
6+
class JSEventLoop : public EventLoopInterfaceV2 {
77
public:
88
JSEventLoop() = default;
99
~JSEventLoop() override = default;
@@ -20,5 +20,7 @@ class JSEventLoop : public EventLoopInterface {
2020
std::unique_ptr<EventSource> addExitEvent(EventCallback callback) override;
2121
std::unique_ptr<EventSource> addDeferEvent(EventCallback callback) override;
2222
std::unique_ptr<EventSource> addPostEvent(EventCallback callback) override;
23+
std::unique_ptr<EventSourceAsync>
24+
addAsyncEvent(EventCallback callback) override;
2325
};
2426
} // namespace fcitx

0 commit comments

Comments
 (0)