File tree Expand file tree Collapse file tree 2 files changed +24
-3
lines changed
src/FsToolkit.ErrorHandling.IcedTasks
tests/FsToolkit.ErrorHandling.IcedTasks.Tests Expand file tree Collapse file tree 2 files changed +24
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments