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 =
18
18
open IcedTasks
19
19
20
20
/// CancellationToken -> Task<Result<'T, 'Error>>
21
- type CancellableTaskResult < 'T , 'Error > = CancellationToken -> TaskResult < 'T, 'Error>
21
+ type CancellableTaskResult < 'T , 'Error > = CancellableTask < Result < 'T, 'Error> >
22
22
23
23
24
24
/// The extra data stored in ResumableStateMachine for tasks
@@ -855,6 +855,13 @@ module CancellableTaskResultCE =
855
855
return Ok r
856
856
}
857
857
858
+
859
+ member inline _.Source ( result : CancellableTask ) : CancellableTaskResult < unit , 'Error > =
860
+ cancellableTask {
861
+ let! r = result
862
+ return Ok r
863
+ }
864
+
858
865
member inline _.Source ( result : ColdTask < _ >) : CancellableTaskResult < _ , _ > =
859
866
fun _ ->
860
867
// 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 =
203
203
task {
204
204
205
205
let ctr =
206
- cancellableTaskResult { return ! fun ct -> Task.CompletedTask }
206
+ cancellableTaskResult { return ! fun ( ct : CancellationToken ) -> Task.CompletedTask }
207
207
208
208
let! actual = ctr CancellationToken.None
209
209
Expect.equal actual ( Ok()) " Should be able to Return! CancellableTask"
@@ -477,10 +477,24 @@ module CancellableTaskResultCE =
477
477
478
478
let ctr =
479
479
cancellableTaskResult {
480
- let! someValue = fun ct -> Task.CompletedTask
480
+ let! someValue = fun ( ct : CancellationToken ) -> Task.CompletedTask
481
481
return someValue
482
482
}
483
483
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
+
484
498
let! actual = ctr CancellationToken.None
485
499
Expect.equal actual ( Ok data) " Should be able to let! CancellableTask"
486
500
}
You can’t perform that action at this time.
0 commit comments