Repository navigation
Deferred callback responses for cppFunction (#459) - #496
Conversation
… by the connection and the server scope (#459)
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟡 Changes recommended
A moderate issue remains where a failed responder task spawn can permanently reserve a call ID because DeferredCalls::finish() is never invoked, potentially causing later requests to be rejected as already in use and leaving a promise hanging.
2 open issues
What changed in this PR
Deferred callback responses for cppFunction: extends WebFront’s JavaScript→C++ bridge so cppFunction callbacks can return a sender (e.g., webfront::ResultTask<R> / ResultTask<void>), and the JavaScript Promise settles when that async work completes. In-flight deferred calls are tracked per connection so disconnect/shutdown stops pending work and late answers are dropped, with docs/ADRs and tests updated accordingly.
Changes:
- Add deferred
cppFunctionexecution path that spawns server-scoped work and correlates responses by per-connection call ID. - Introduce public
webfront::ResultTask<R>alias for result-bearing coroutine/sender returns. - Add Catch2 + Jasmine coverage and update async execution documentation plus ADRs/contributor guidance.
Review notes (must address):
- (moderate, include/webfront/WebFront.hpp:1032)
startDeferred()invokes the callback before reserving the callId; rejected calls may still trigger side effects—reserve first. - (moderate, include/webfront/WebFront.hpp:369)
makeValueFrame()only catchesstd::exception; catch unknown exceptions too to avoidterminate()for non-std throws during encoding. - (moderate, include/webfront/WebFront.hpp:1054) If responder task spawn is rejected, the call ID can remain reserved indefinitely because
finish()is never reached—ensure cleanup on spawn failure. - (nit, include/webfront/DeferredCalls.hpp:40) Tighten the deferred sender concept so “at most one value” constraints fail at the concept boundary with the intended diagnostics.
- (nit, include/webfront/WebFront.hpp:1076) Instantiate
detail::deferred_value_t<Sender>to trigger the dedicated static_assert diagnostics for multi-value senders.
| File | Summary |
|---|---|
test/web/suite/specs/webfront-specs.mjs |
Adds browser integration specs for deferred Promise resolution/rejection and out-of-order completion. |
test/web/JasmineTest.cpp |
Registers deferred C++ callbacks used by the Jasmine suite. |
test/unit/DeferredCallTests.cpp |
Adds unit tests for deferred result, exceptions (pre/post-suspension), stop, void task, concurrency, duplicate IDs, disconnect, and shutdown. |
test/unit/CMakeLists.txt |
Wires the new unit tests into the build/unity configuration. |
include/webfront/WebFront.hpp |
Implements deferred callback dispatch, connection-scoped tracking, and deferred response sending. |
include/webfront/Task.hpp |
Adds public webfront::ResultTask<R> alias for result-bearing coroutines/senders. |
include/webfront/DeferredCalls.hpp |
Adds per-connection tracking for in-flight deferred calls and cancellation/finish handling. |
docs/ASYNC_EXECUTION.md |
Documents deferred callback semantics, lifecycle rules, and usage. |
docs/adr/ADR-020-services-systeme.md |
Updates ADR-020 example/assumptions to reflect deferred cppFunction support. |
docs/adr/ADR-004-appels-asynchrones-et-erreurs.md |
Updates ADR-004 (v2.6) to describe deferred callback responses and error behavior. |
AGENTS.md |
Updates contributor guidance to mention sender-returning cppFunction callbacks and lifecycle behavior. |
This pull request requires changes.
Review effort: Balanced
… are compiled together (#459)
|
Both points are fixed in e068b40 (the deferred-call code lives in this PR):
|


Part of #448 (system services, step 3). Closes #459. Stacked on #494: the base becomes
developonce it is merged.cppFunctionaccepts a callback that returns a sender (awebfront::ResultTask<R>coroutine, new public alias ofex::task<R>, orResultTask<void>). The JavaScript Promise settles when it completes, with the encoded value, or rejects with its message and code (#458); a sender that completes stopped without a stop request rejects withwebfront.cancelled.detail::DeferredCalls): the browser's disconnection stops it and drops the late answer; shutdown stops and joins it. The answer is sent on the server context.webfront.malformedand the running call is untouched. Saturation is JavaScript's existing 65,535 outstanding calls limit.ADR-004 2.6,
docs/ASYNC_EXECUTION.md, AGENTS.md and the ADR-020 example are updated.Tests
DeferredCallTests): deferred result, exception before and after suspension, stopped operation,voidtask, caller-taking callback, concurrent calls, duplicate identifier, disconnection while waiting, shutdown while waiting.ctest -L fastpasses with CEF off.