Skip to content

Sync fork with upstream PRs #14 and #17 (ordered merge) - #1

Merged
TheOriginalBytePlayer merged 7 commits into
mainfrom
copilot/merge-upstream-into-main
Aug 9, 2026
Merged

Sync fork with upstream PRs #14 and #17 (ordered merge)#1
TheOriginalBytePlayer merged 7 commits into
mainfrom
copilot/merge-upstream-into-main

Conversation

Copilot AI commented Aug 9, 2026

Copy link
Copy Markdown

This PR brings selected upstream work from Laurensvanrun/Delphi-Promises into the fork by merging PRs in the requested order: Laurensvanrun#14 first, then Laurensvanrun#17. The goal is to align the fork with upstream promise behavior and newly added promise capabilities without rebasing history.

  • Merge scope

  • Core library updates

    • Updated promise internals in Core/Types/Next.Core.Promises.pas and related core types.
    • Added new units for cancellation and exception-oriented promise flow:
      • Core/Types/Next.Core.Promises.Cancellation.pas
      • Core/Types/Next.Core.Promises.Exceptions.pas
    • Included upstream fixes in disposable/promise lifecycle handling.
  • API surface and behavior additions

    • Synced upstream support and docs for higher-level combinators and control flow (Race, Any, AllSettled, Timeout, Cancellation, Finally).
  • Test suite alignment

    • Brought in upstream test coverage for the newly synced behavior via dedicated promise test modules (Any/Race/AllSettled/Timeout/Cancellation/Exceptions/Finally).
TPromise<Integer>.Any([
  TPromise<Integer>.Resolve(42),
  TPromise<Integer>.Reject(Exception.Create('fail'))
]).&Then(
  procedure(const Value: Integer)
  begin
    // Resolves with first successful promise
  end
);

tk-tmssoftware and others added 7 commits December 20, 2024 11:33
…Timeout support

Extend the Delphi-Promises library with six new features:

1. Promise.Race<T> - Resolves/rejects with the first settled promise
2. Promise.Any<T> - Resolves with first success, rejects with EAggregateException if all fail
3. Promise.AllSettled<T> - Waits for all promises, returns array of TPromiseSettledResult<T>
4. Cancellation support - ICancellationToken/ICancellationTokenSource with cooperative cancellation
5. .Timeout method - Rejects with ETimeoutException if promise doesn't settle in time
6. Additional .Finally tests - Verifying existing Finally behavior per spec

New files:
- Core/Types/Next.Core.Promises.Exceptions.pas (EAggregateException, ETimeoutException, EOperationCancelled)
- Core/Types/Next.Core.Promises.Cancellation.pas (ICancellationToken, ICancellationTokenSource, TCancellationTokenSource)
- Test/Types/TestPromiseRace.pas (8 tests including stress test)
- Test/Types/TestPromiseAny.pas (7 tests including stress test)
- Test/Types/TestPromiseAllSettled.pas (6 tests including stress test)
- Test/Types/TestPromiseFinally.pas (6 tests)
- Test/Types/TestPromiseCancellation.pas (9 tests)
- Test/Types/TestPromiseTimeout.pas (4 tests)

Modified files:
- Core/Types/Next.Core.Promises.pas (Race, Any, AllSettled, CancelToken, IsCancelled, OnCancelled, Timeout)
- Test/TestNext.dpr (references to new units and test fixtures)

https://claude.ai/code/session_01VeVVLGmQXiukbpfM5p7W99
…ents-euyZO

Add Promise.Race, Promise.Any, Promise.AllSettled, Cancellation, and Timeout support
Replace 6 non-generic test files with generic versions testing across
5 types (Integer, Boolean, String, TSimpleRecord, TMyObject) plus a
new exception type test file. Fix two library bugs discovered during
testing:

- Promise.Race: use dvKeep + manual loser disposal to prevent
  double-free of object-typed values
- Promise.Any: fix variable capture bug in rejection slot tracking;
  use atomic counter instead of captured loop index

Fix variable capture bugs in AllSettled and Race stress tests by
extracting promise creation into helper functions.

750 tests, 0 failures, 0 errors.
…Finally docs

Add comprehensive documentation with code examples, comparison tables
to JavaScript equivalents, and API reference for all new promise
combinators and features.
Co-authored-by: TheOriginalBytePlayer <18058224+TheOriginalBytePlayer@users.noreply.github.com>
Co-authored-by: TheOriginalBytePlayer <18058224+TheOriginalBytePlayer@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR syncs upstream promise functionality and tests into the fork (merging upstream PRs Laurensvanrun#14 then Laurensvanrun#17), adding higher-level promise combinators and control-flow features (Race/Any/AllSettled/Timeout/Cancellation/Finally), plus related exception types and test coverage.

Changes:

  • Added new promise APIs (Race/Any/AllSettled/Timeout/Cancellation/Finally) and supporting types in core units.
  • Introduced dedicated exceptions and cancellation-token units.
  • Aligned/expanded the DUnitX test suite and updated test project references and documentation.

Reviewed changes

Copilot reviewed 16 out of 28 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
Core/Types/Next.Core.Promises.pas Adds new promise APIs (Race/Any/AllSettled/Timeout/Cancellation/Finally) and updates scheduler/cancellation propagation.
Core/Types/Next.Core.Promises.Exceptions.pas Introduces timeout/cancellation/aggregate exception types used by new APIs.
Core/Types/Next.Core.Promises.Cancellation.pas Adds cancellation token source/token interfaces and implementation.
Core/Types/Next.Core.DisposableValue.pas Refactors locals/inline vars for disposal helpers (likely compiler-compat fixes).
Test/Types/TestPromiseTimeout.pas Adds Timeout behavior tests (success, rejection, custom message, chaining).
Test/Types/TestPromiseRace.pas Adds Race combinator tests including concurrency/stress patterns.
Test/Types/TestPromiseFinally.pas Adds Finally behavior tests (pass-through, replacement on raise, Main thread variant).
Test/Types/TestPromiseExceptions.pas Adds tests validating new exception messages/aggregate behavior.
Test/Types/TestPromiseCancellation.pas Adds cancellation token and CancelToken/OnCancelled behavior tests.
Test/Types/TestPromiseAny.pas Adds Any combinator tests including aggregate-rejection behavior.
Test/Types/TestPromiseAllSettled.pas Adds AllSettled tests for mixed outcomes, ordering, and concurrency.
Test/Types/Next.Core.TestPromises.pas Removes CodeSiteLogging dependency from test harness uses.
Test/TestNext.dproj Registers new core units + new test units in the test project.
Test/TestNext.dpr Adds new units/tests to the DUnitX test runner uses list.
Test/Next.Core.Test.Assert.pas Adds optional Spring4D integration and RTTI fallback in assertions.
Test/DelphiMocks/VSoft.DelphiMocks.dspec Normalizes formatting/line endings (content unchanged).
Test/DelphiMocks/Tests/MemoryLeakTest/FastMM4Options.inc Normalizes formatting/line endings (content unchanged).
Test/DelphiMocks/Tests/.gitignore Normalizes formatting/line endings (content unchanged).
Test/DelphiMocks/Source/Delphi.Mocks.inc Normalizes formatting/line endings (content unchanged).
Test/DelphiMocks/README.md Normalizes formatting/line endings (content unchanged).
Test/DelphiMocks/LICENSE.txt Normalizes formatting/line endings (content unchanged).
Test/DelphiMocks/Build/TestAndBuild.fbp8 Normalizes formatting/line endings (content unchanged).
Test/DelphiMocks/.gitmodules Normalizes formatting/line endings (content unchanged).
Test/DelphiMocks/.gitignore Updates ignore patterns; currently contains a merge-artifact marker.
readme.md Expands documentation to cover new combinators/timeout/cancellation/finally.
LICENSE Normalizes formatting/line endings (content unchanged).
.github/ISSUE_TEMPLATE/feature_request.md Normalizes template formatting/line endings.
.github/ISSUE_TEMPLATE/bug_report.md Normalizes template formatting/line endings.
Suppressed comments (1)

Test/Next.Core.Test.Assert.pas:161

  • Assert.AreNotEqualCore: SEqualsErrorStr2 is only declared under {$IFNDEF SPRING4D} but it is used unconditionally. Enabling SPRING4D will make this unit fail to compile due to an undefined identifier.
class procedure Assert.AreNotEqualCore(const expected, actual: TValue; const AMessage: string);
{$IFNDEF SPRING4D}
const
  SEqualsErrorStr2 = 'Expected value and actual value should not be equal. Expected: %s Actual: %s %s';
{$ENDIF}
begin
  DoAssert;
  if expected.Equals(actual) then
    FailFmt(SEqualsErrorStr2, [expected.ToString, actual.ToString, AMessage], ReturnAddress)
end;

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1004 to +1011
APromises[i].ThenBy(
function(const AValue: T): T
begin
Result := AValue;
if TInterlocked.CompareExchange(LResolved, 1, 0) = 0 then
TFirstPromise<T>(LOuterPromise).Resolve(AValue);
end)
.Catch(
Comment on lines +992 to +994
SetLength(LExceptions, LTotalCount);
LLock := TCriticalSection.Create;

Comment on lines +1078 to +1081
LResult.Status := TPromiseStatus.psRejected;
LResult.Value := Default(T);
LResult.Error := APromises[i].GetFailure.Reason;
end;
*.rc
*.drc
*.map
=======
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.

6 participants