8000 [k2] fix set_timer by using task<> to start a fork by apolyakov · Pull Request #1328 · VKCOM/kphp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[k2] fix set_timer by using task<> to start a fork #1328

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions runtime-light/stdlib/time/timer-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
#include <chrono>
#include <concepts>
#include <cstdint>
#include <functional>
#include <utility>

#include "runtime-light/coroutine/awaitable.h"
#include "runtime-light/coroutine/shared-task.h"
#include "runtime-light/coroutine/task.h"
#include "runtime-light/utils/logs.h"

Expand All @@ -20,10 +20,10 @@ kphp::coro::task<> f$set_timer(int64_t timeout_ms, T on_timer_callback) noexcept
kphp::log::warning("can't set timer for negative duration {} ms", timeout_ms);
co_return;
}
const auto fork_f{[](std::chrono::nanoseconds duration, T&& on_timer_callback) -> kphp::coro::shared_task<> {
const auto timer_f{[](std::chrono::nanoseconds duration, T on_timer_callback) noexcept -> kphp::coro::task<> {
co_await wait_for_timer_t{duration};
on_timer_callback();
std::invoke(std::move(on_timer_callback));
}}; // TODO: someone should pop that fork from ForkComponentContext since it will stay there unless we perform f$wait on fork
const auto duration_ms{std::chrono::milliseconds{static_cast<uint64_t>(timeout_ms)}};
co_await start_fork_t{fork_f(std::chrono::duration_cast<std::chrono::nanoseconds>(duration_ms), std::move(on_timer_callback))};
co_await start_fork_t{std::invoke(timer_f, std::chrono::duration_cast<std::chrono::nanoseconds>(duration_ms), std::move(on_timer_callback))};
}
Loading
0