Skip to content

Commit d61158b

Browse files
committed
Fixes CancellationTask overload
1 parent 52d5304 commit d61158b

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/FsToolkit.ErrorHandling.IcedTasks/CancellableTaskResultCE.fs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module CancellableTaskResultCE =
1818
open IcedTasks
1919

2020
/// CancellationToken -> Task<Result<'T, 'Error>>
21-
type CancellableTaskResult<'T, 'Error> = CancellationToken -> TaskResult<'T, 'Error>
21+
type CancellableTaskResult<'T, 'Error> = CancellableTask<Result<'T, 'Error>>
2222

2323

2424
/// The extra data stored in ResumableStateMachine for tasks
@@ -855,6 +855,13 @@ module CancellableTaskResultCE =
855855
return Ok r
856856
}
857857

858+
859+
member inline _.Source(result: CancellableTask) : CancellableTaskResult<unit, 'Error> =
860+
cancellableTask {
861+
let! r = result
862+
return Ok r
863+
}
864+
858865
member inline _.Source(result: ColdTask<_>) : CancellableTaskResult<_, _> =
859866
fun _ ->
860867
// TODO: using `coldTask` results in "internal error: The local field ResumptionDynamicInfo was referenced but not declare" compliation error

tests/FsToolkit.ErrorHandling.IcedTasks.Tests/CancellableTaskResultCE.fs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ module CancellableTaskResultCE =
203203
task {
204204

205205
let ctr =
206-
cancellableTaskResult { return! fun ct -> Task.CompletedTask }
206+
cancellableTaskResult { return! fun (ct : CancellationToken) -> Task.CompletedTask }
207207

208208
let! actual = ctr CancellationToken.None
209209
Expect.equal actual (Ok()) "Should be able to Return! CancellableTask"
@@ -477,10 +477,24 @@ module CancellableTaskResultCE =
477477

478478
let ctr =
479479
cancellableTaskResult {
480-
let! someValue = fun ct -> Task.CompletedTask
480+
let! someValue = fun (ct : CancellationToken) -> Task.CompletedTask
481481
return someValue
482482
}
483483

484+
let! actual = ctr CancellationToken.None
485+
Expect.equal actual (Ok data) "Should be able to let! CancellableTask"
486+
}
487+
testCaseTask "do! CancellableTask"
488+
<| fun () ->
489+
task {
490+
let data = ()
491+
492+
let ctr =
493+
cancellableTaskResult {
494+
do! fun (ct : CancellationToken) -> Task.CompletedTask
495+
// return someValue
496+
}
497+
484498
let! actual = ctr CancellationToken.None
485499
Expect.equal actual (Ok data) "Should be able to let! CancellableTask"
486500
}

0 commit comments

Comments
 (0)