Skip to content

refactor(xpp): rename defer() to lazy() — lazy promise semantics - #91

Merged
mivinci merged 1 commit into
mainfrom
pi/rename-defer-to-lazy
Aug 28, 2026
Merged

mivinci merged 1 commit into
mainfrom
pi/rename-defer-to-lazy

Conversation

@mivinci

@mivinci mivinci commented Aug 28, 2026

Copy link
Copy Markdown
Owner

Summary

Rename xpp::defer() → xpp::lazy().

defer was misleading: in Go it means run-at-scope-exit cleanup, but xpp's defer(fn) is a lazy promise wrapper — the function runs on first poll(), not when scheduled, and may never run if never polled (discussed in issue #82's context). lazy is the established term for lazy evaluation (C++26 std::lazy / P2500, Kotlin lazy {}, Lazy<T>).

Changes

  • libxpp/xpp/promise.h: defer() → lazy() (definition + doc)
  • libxpp/xpp/spawn.h: spawn(Func) now wraps via xpp::lazy (it was the only caller of defer)
  • Tests: promise_test.cpp, spawn_test.cpp, http/server_test.cpp updated
  • Docs: promise/README.md, promise/timers.md updated
  • issues/coro-nested-spawn-capture-lambda-crash.md: wording updated

Adjective uses of "deferred/defer" (deferred resolution, deferred member impl, "spawn defers execution") are deliberately untouched — those are English words, not the function name.

Verification

  • C++20 build: 0 errors
  • xpp tests: 73/73 (ASan)
  • C++11: unchanged (co-routine code is behind XPP_HAS_COROUTINES; lazy() itself is C++11-compatible)

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.
@mivinci
mivinci merged commit 3af6742 into main Aug 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant