Skip to content

Add cancellableValueTaskOption and cancellableValueTaskResult CEs for IcedTasks#349

Merged
TheAngryByrd merged 4 commits into
masterfrom
copilot/add-cancellable-valuetask-ce
Feb 25, 2026
Merged

Add cancellableValueTaskOption and cancellableValueTaskResult CEs for IcedTasks#349
TheAngryByrd merged 4 commits into
masterfrom
copilot/add-cancellable-valuetask-ce

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 24, 2026

  • Explore codebase and understand structure
  • Wire up existing CancellableTaskOption files into library fsproj
  • Wire up existing CancellableTaskOption test file into tests fsproj
  • Create CancellableValueTaskResultCE.fs (new source file, inherits from CancellableTaskResultBuilderBase)
  • Create CancellableValueTaskOptionCE.fs (new source file with new state machine types using AsyncValueTaskMethodBuilder)
  • Add new source files to library fsproj
  • Create test file for CancellableValueTaskResultCE
  • Create test file for CancellableValueTaskOptionCE
  • Add new test files to tests fsproj
  • Fix nullness warning in CancellableTaskOptionCE.fs (ICriticalNotifyCompletion downcast)
  • Fix BackgroundCancellableValueTaskOptionBuilder SetResult bug
  • Fix some to use direct fun _ -> ValueTask<'a option>(Some x) (avoids state machine creation)
  • Fix ReturnFrom parameter label to use correct non-option Bind
  • Add doc comments to extension methods on Async, AsyncEx, and AsyncOptionBuilder in CancellableValueTaskOptionCE.fs
  • Add gitbook documentation for cancellableValueTaskOption (ce, bind, apply, map, zip, either, others)
  • Add gitbook documentation for cancellableValueTaskResult (index, ce, bind, apply, map, zip)
  • Update SUMMARY.md with new documentation entries
  • Run tests - all 329 tests pass
  • Format code and verify formatting passes
Original prompt

This section details on the original issue you should resolve

<issue_title>Add cancellableValueTaskOption and cancellableValueTaskResult (for IcedTasks)</issue_title>
<issue_description>I find myself in need of a Option/Result CEs for the cancellable IcedTasks CEs, particularly for cancellableValueTask.

Unfortunately I can't help with this, because the builder for cancellableValueTask (which I assume must be replicated and adjusted?) is far above my level. But I thought I'd post this issue anyway.

One could of course add Option/Result CEs for all the IcedTask CEs. I'm currently only using the cancellable ones.</issue_description>

<agent_instructions>- Make sure you've added tests and they pass

Comments on the Issue (you are @copilot in this section)


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

… IcedTasks

Co-authored-by: TheAngryByrd <1490044+TheAngryByrd@users.noreply.github.com>
Copilot AI changed the title [WIP] Add cancellableValueTaskOption and cancellableValueTaskResult for IcedTasks Add cancellableValueTaskOption and cancellableValueTaskResult CEs for IcedTasks Feb 24, 2026
Copilot AI requested a review from TheAngryByrd February 24, 2026 20:23
@TheAngryByrd TheAngryByrd requested a review from Copilot February 25, 2026 02:07
Copy link
Copy Markdown

Copilot AI left a comment

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 adds Option and Result computation expressions for CancellableValueTask<'T> to the FsToolkit.ErrorHandling.IcedTasks library, enabling ergonomic short-circuit semantics without allocating Task objects. Additionally, it registers previously unimplemented cancellableTaskOption / backgroundCancellableTaskOption CEs and fixes a nullness warning in CancellableTaskOptionCE.fs.

Changes:

  • Added cancellableValueTaskResult and backgroundCancellableValueTaskResult CEs that inherit from the existing CancellableTaskResultBuilderBase and use AsyncValueTaskMethodBuilder<Result<'T, 'Error>>
  • Added cancellableValueTaskOption and backgroundCancellableValueTaskOption CEs with self-contained state machine implementation using AsyncValueTaskMethodBuilder<'T option>
  • Registered previously unimplemented cancellableTaskOption / backgroundCancellableTaskOption CEs by adding them to the fsproj file
  • Fixed FS3264 nullness warning by replacing unsafe :?> downcast with safe match ... :? pattern in CancellableTaskOptionCE.fs

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/FsToolkit.ErrorHandling.IcedTasks/FsToolkit.ErrorHandling.IcedTasks.fsproj Adds CancellableTaskOptionBuilderBase, CancellableTaskOptionCE, CancellableValueTaskResultCE, and CancellableValueTaskOptionCE to project compilation
src/FsToolkit.ErrorHandling.IcedTasks/CancellableValueTaskResultCE.fs Implements Result CE for CancellableValueTask, inheriting from CancellableTaskResultBuilderBase with companion module functions
src/FsToolkit.ErrorHandling.IcedTasks/CancellableValueTaskOptionCE.fs Implements Option CE for CancellableValueTask with self-contained state machine and companion module functions
src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskOptionCE.fs Fixes nullness warning by replacing unsafe cast with safe pattern match
tests/FsToolkit.ErrorHandling.IcedTasks.Tests/FsToolkit.ErrorHandling.IcedTasks.Tests.fsproj Registers new test files for CancellableTaskOptionCE, CancellableValueTaskResultCE, and CancellableValueTaskOptionCE
tests/FsToolkit.ErrorHandling.IcedTasks.Tests/CancellableValueTaskResultCE.fs Comprehensive tests for CancellableValueTaskResult CE including return, bind, cancellation, and exception handling
tests/FsToolkit.ErrorHandling.IcedTasks.Tests/CancellableValueTaskOptionCE.fs Comprehensive tests for CancellableValueTaskOption CE including return, bind, None short-circuit, cancellation, and exception handling

Comment thread src/FsToolkit.ErrorHandling.IcedTasks/CancellableValueTaskOptionCE.fs Outdated
Copy link
Copy Markdown
Collaborator

@TheAngryByrd TheAngryByrd left a comment

Choose a reason for hiding this comment

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

@copilot Fix comments. Make sure to add doc comments to any public method/function that missing them in this PR. Also this PR is missing gitbook documentation.

Co-authored-by: TheAngryByrd <1490044+TheAngryByrd@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 25, 2026

@copilot Fix comments. Make sure to add doc comments to any public method/function that missing them in this PR. Also this PR is missing gitbook documentation.

Fixed in 8543e47 — the some double-wrap is corrected, doc comments added to all public Async/AsyncEx/AsyncOptionBuilder extension methods in CancellableValueTaskOptionCE.fs, and gitbook documentation added for both cancellableValueTaskOption (ce, bind, apply, map, zip, either, others) and cancellableValueTaskResult (index, ce, bind, apply, map, zip) with SUMMARY.md updated accordingly.

Copy link
Copy Markdown
Collaborator

@TheAngryByrd TheAngryByrd left a comment

Choose a reason for hiding this comment

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

@copilot Found something else. Check for any uses of a computation expression that doesn't do any binds and make sure they return a simplier version that doesn't create state machines.

Comment thread src/FsToolkit.ErrorHandling.IcedTasks/CancellableValueTaskOptionCE.fs Outdated
Co-authored-by: TheAngryByrd <1490044+TheAngryByrd@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 25, 2026

@copilot Found something else. Check for any uses of a computation expression that doesn't do any binds and make sure they return a simplier version that doesn't create state machines.

Fixed in 3d67762. CancellableValueTaskOption.some was the only function without binds using a CE — it now returns fun _ -> ValueTask<'a option>(Some x) directly. All other helpers (bind, map, apply, zip, parallelZip) use let! binds and are appropriate as CEs. CancellableValueTaskResult.singleton already used the direct approach.

Copilot AI requested a review from TheAngryByrd February 25, 2026 02:41
@TheAngryByrd TheAngryByrd marked this pull request as ready for review February 25, 2026 02:42
@TheAngryByrd TheAngryByrd merged commit d10f132 into master Feb 25, 2026
26 checks passed
TheAngryByrd added a commit that referenced this pull request Feb 27, 2026
- [Add IAsyncEnumerable support to task computation expressions](#347) Credits @Copilot
- [Add `valueTaskValueOption` CE for `ValueTask<'T voption>` computation expressions](#348) Credits @Copilot
- [Add `cancellableValueTaskOption` and `cancellableValueTaskResult` CEs for IcedTasks](#349) Credits @Copilot
- [Add `Source` overloads to `taskResultOption` CE for interop with `Result`, `TaskResult`, `Option`, `Task`, and `Async`](#351) Credits @Copilot
- [Add `requireSomeWith` and `requireNoneWith` for lazy error evaluation](#352) Credits @Copilot
- [Add `TaskResult.ofCatchTask`](#353) Credits @Copilot
- [Add comprehensive gitbook documentation for all public API surface](#354) Credits @Copilot
TheAngryByrd added a commit that referenced this pull request Feb 27, 2026
- [Add IAsyncEnumerable support to task computation expressions](#347) Credits @Copilot
- [Add `valueTaskValueOption` CE for `ValueTask<'T voption>` computation expressions](#348) Credits @Copilot
- [Add `cancellableValueTaskOption` and `cancellableValueTaskResult` CEs for IcedTasks](#349) Credits @Copilot
- [Add `Source` overloads to `taskResultOption` CE for interop with `Result`, `TaskResult`, `Option`, `Task`, and `Async`](#351) Credits @Copilot
- [Add `requireSomeWith` and `requireNoneWith` for lazy error evaluation](#352) Credits @Copilot
- [Add `TaskResult.ofCatchTask`](#353) Credits @Copilot
- [Add comprehensive gitbook documentation for all public API surface](#354) Credits @Copilot
TheAngryByrd added a commit that referenced this pull request Feb 27, 2026
- [Add IAsyncEnumerable support to task computation expressions](#347) Credits @Copilot
- [Add `valueTaskValueOption` CE for `ValueTask<'T voption>` computation expressions](#348) Credits @Copilot
- [Add `cancellableValueTaskOption` and `cancellableValueTaskResult` CEs for IcedTasks](#349) Credits @Copilot
- [Add `Source` overloads to `taskResultOption` CE for interop with `Result`, `TaskResult`, `Option`, `Task`, and `Async`](#351) Credits @Copilot
- [Add `requireSomeWith` and `requireNoneWith` for lazy error evaluation](#352) Credits @Copilot
- [Add `TaskResult.ofCatchTask`](#353) Credits @Copilot
- [Add comprehensive gitbook documentation for all public API surface](#354) Credits @Copilot

Remove AutoGPT subproject reference
TheAngryByrd added a commit that referenced this pull request Feb 27, 2026
- [Add IAsyncEnumerable support to task computation expressions](#347) Credits @Copilot
- [Add `valueTaskValueOption` CE for `ValueTask<'T voption>` computation expressions](#348) Credits @Copilot
- [Add `cancellableValueTaskOption` and `cancellableValueTaskResult` CEs for IcedTasks](#349) Credits @Copilot
- [Add `Source` overloads to `taskResultOption` CE for interop with `Result`, `TaskResult`, `Option`, `Task`, and `Async`](#351) Credits @Copilot
- [Add `requireSomeWith` and `requireNoneWith` for lazy error evaluation](#352) Credits @Copilot
- [Add `TaskResult.ofCatchTask`](#353) Credits @Copilot
- [Add comprehensive gitbook documentation for all public API surface](#354) Credits @Copilot

Remove AutoGPT subproject reference
TheAngryByrd added a commit that referenced this pull request Feb 27, 2026
- [Add IAsyncEnumerable support to task computation expressions](#347) Credits @Copilot
- [Add `valueTaskValueOption` CE for `ValueTask<'T voption>` computation expressions](#348) Credits @Copilot
- [Add `cancellableValueTaskOption` and `cancellableValueTaskResult` CEs for IcedTasks](#349) Credits @Copilot
- [Add `Source` overloads to `taskResultOption` CE for interop with `Result`, `TaskResult`, `Option`, `Task`, and `Async`](#351) Credits @Copilot
- [Add `requireSomeWith` and `requireNoneWith` for lazy error evaluation](#352) Credits @Copilot
- [Add `TaskResult.ofCatchTask`](#353) Credits @Copilot
- [Add comprehensive gitbook documentation for all public API surface](#354) Credits @Copilot
TheAngryByrd added a commit that referenced this pull request Feb 27, 2026
- [Add IAsyncEnumerable support to task computation expressions](#347) Credits @Copilot
- [Add `valueTaskValueOption` CE for `ValueTask<'T voption>` computation expressions](#348) Credits @Copilot
- [Add `cancellableValueTaskOption` and `cancellableValueTaskResult` CEs for IcedTasks](#349) Credits @Copilot
- [Add `Source` overloads to `taskResultOption` CE for interop with `Result`, `TaskResult`, `Option`, `Task`, and `Async`](#351) Credits @Copilot
- [Add `requireSomeWith` and `requireNoneWith` for lazy error evaluation](#352) Credits @Copilot
- [Add `TaskResult.ofCatchTask`](#353) Credits @Copilot
- [Add comprehensive gitbook documentation for all public API surface](#354) Credits @Copilot

Remove AutoGPT subproject reference
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.

Add cancellableValueTaskOption and cancellableValueTaskResult (for IcedTasks)

3 participants