wƒWebFront C++23
FR ↗GitHub ↗

Background concepts / WEBFRONT

Modern C++ and asynchrony

Lifetimes, coroutines and cancellation.

Lifetime before syntax

WebFront is header-only and requires C++23. A registered callback may outlive the function that registered it: its captures must remain valid. Do not capture a local by reference if it will be destroyed before the callback. The application owns its callbacks and must remain alive while they are used.

A coroutine is not a thread

C++20 introduced co_await: a coroutine can suspend while waiting for an operation. This does not automatically make CPU computation non-blocking. WebFront application tasks return webfront::Task and start with app.spawn(task) or ui.spawn(task). The application owns and drains them before destruction.

Choose an asynchronous result

The following assumes a valid ui and a registered JavaScript getTitle function. The typed sender propagates local cancellation through the coroutine’s stop token. Retain a TaskHandle to request individual cancellation. Local cancellation does not stop JavaScript that has already started. Futures and Promises do not expose this cancellation, and there is no automatic timeout.

C++23
// Inside a webfront::Task coroutine:
auto title = co_await ui.jsFunctionSender<std::string>("getTitle")();

Question

Does co_await automatically create a thread?