Skip to content

Commit 8ea326a

Browse files
refactor: use atomic to notify if js is ready
1 parent b9806c3 commit 8ea326a

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/shell/entry.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void main() {
182182
init_render_global();
183183
ShowWindow(GetConsoleWindow(), SW_SHOW);
184184
std::thread([]() {
185-
script_ctx.js_ready_future.wait();
185+
script_ctx.is_js_ready.wait(true);
186186
script_ctx.js->enqueueJob([]() {
187187
script_ctx.js->eval("globalThis.showConfigPage()", "asan.js");
188188
});

src/shell/script/script.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ void script_context::watch_folder(const std::filesystem::path &path,
122122
dbgout("Creating JS thread");
123123
menu_callbacks_js.clear();
124124

125+
is_js_ready.exchange(false);
125126
js_thread.emplace(
126127
[&, this, ss = stop_signal]() {
127128
CPPTRACE_TRY {
@@ -131,7 +132,8 @@ void script_context::watch_folder(const std::filesystem::path &path,
131132
rt = std::make_shared<qjs::Runtime>();
132133
JS_UpdateStackTop(rt->rt);
133134
js = std::make_shared<qjs::Context>(*rt);
134-
js_ready_promise.set_value();
135+
136+
is_js_ready.exchange(true);
135137
bind();
136138
try {
137139
JS_UpdateStackTop(rt->rt);

src/shell/script/script.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@ struct script_context {
1616
std::shared_ptr<qjs::Runtime> rt;
1717
std::shared_ptr<qjs::Context> js;
1818

19-
private:
20-
std::promise<void> js_ready_promise{};
2119

2220
public:
23-
std::future<void> js_ready_future = js_ready_promise.get_future();
21+
std::atomic<bool> is_js_ready{false};
2422

2523
std::shared_ptr<int> stop_signal = std::make_shared<int>(0);
2624
script_context();

0 commit comments

Comments
 (0)