Repository navigation
refactor(xpp): rename defer() to lazy() — lazy promise semantics - #91
Merged
Merged
Conversation
defer() was confusing: in Go, defer means run-at-scope-exit cleanup;
xpp's defer is a lazy promise wrapper (runs on first poll, not when
scheduled). Rename to lazy(), matching C++26 std::lazy (P2500) and
Kotlin's lazy {} — the established term for lazy evaluation.
- promise.h: defer() -> lazy(); doc updated
- spawn.h: spawn(Func) wraps via xpp::lazy instead of xpp::defer
- Tests: promise_test, spawn_test, http/server_test updated
- docs: promise/README.md, promise/timers.md updated
- issues: coro-nested-spawn doc wording
Adjective uses (deferred resolve, deferred member impl, spawn defers
*execution*) are untouched — those are not the function name.
Verified: C++20 build 0 errors, xpp 73/73 (ASan), C++11 build clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rename
xpp::defer()→xpp::lazy().deferwas misleading: in Go it means run-at-scope-exit cleanup, but xpp'sdefer(fn)is a lazy promise wrapper — the function runs on firstpoll(), not when scheduled, and may never run if never polled (discussed in issue #82's context).lazyis the established term for lazy evaluation (C++26std::lazy/ P2500, Kotlinlazy {},Lazy<T>).Changes
libxpp/xpp/promise.h:defer()→lazy()(definition + doc)libxpp/xpp/spawn.h:spawn(Func)now wraps viaxpp::lazy(it was the only caller ofdefer)promise_test.cpp,spawn_test.cpp,http/server_test.cppupdatedpromise/README.md,promise/timers.mdupdatedissues/coro-nested-spawn-capture-lambda-crash.md: wording updatedAdjective uses of "deferred/defer" (deferred resolution, deferred member impl, "spawn defers execution") are deliberately untouched — those are English words, not the function name.
Verification
XPP_HAS_COROUTINES;lazy()itself is C++11-compatible)