14std::shared_ptr<
void> startDelayedJsThreadTask(
16 std::chrono::milliseconds delay)
21 std::optional<
int> timerId;
24 auto context =
std::make_shared<Context>();
25 context->task =
std::move(task);
27 int timerId = jsState.eval<QNapi::Number>(
28 "Global.setTimeout(*)",
30 [context](
const CallbackInfo &cbInfo) {
32 auto task = std::exchange(context->task,
nullptr);
33 context->timerId.reset();
34 task(cbInfo.jsState());
37 std::max(delay, std::chrono::milliseconds(0)).count(),
39 context->timerId = timerId;
41 return QtOhos::makeDestroyNotifier(
43 if (context->timerId.has_value()) {
45 [&](JsState &jsState) {
46 jsState.eval(
"Global.clearTimeout(*)", {context->timerId.value()});
49 context->task =
nullptr;
50 context->timerId.reset();