File tree Expand file tree Collapse file tree 1 file changed +65
-0
lines changed
src/FSharp.Control.TaskSeq.Test Expand file tree Collapse file tree 1 file changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -80,3 +80,68 @@ let ``CE taskSeq: use 'let!' with a non-generic task`` () =
80
80
}
81
81
|> verifyEmpty
82
82
|> Task.map ( fun _ -> value |> should equal 1 )
83
+
84
+ [<Fact>]
85
+ let ``CE taskSeq : use 'let ! ' with Async`` () =
86
+ let mutable value = 0
87
+
88
+ taskSeq {
89
+ do value <- value + 1
90
+ let! _ = Async.Sleep 50
91
+ do value <- value + 1
92
+ }
93
+ |> verifyEmpty
94
+ |> Task.map ( fun _ -> value |> should equal 2 )
95
+
96
+ [<Fact>]
97
+ let ``CE taskSeq : use 'let ! ' with Async - mutables`` () =
98
+ let mutable value = 0
99
+
100
+ taskSeq {
101
+ do ! async { value <- value + 1 }
102
+ let! x = async { return value + 1 }
103
+ do ! Async.Sleep 50
104
+ do ! async { value <- value + 1 }
105
+ let! ret = async { return value + 1 }
106
+ yield x + ret // eq 6
107
+ }
108
+ |> TaskSeq.exactlyOne
109
+ |> Task.map ( fun _ -> value |> should equal 6 )
110
+
111
+ [<Fact>]
112
+ let ``CE taskSeq : use 'let ! ' with all kinds of overloads at once`` () =
113
+ let mutable value = 0
114
+
115
+ // this test should be expanded in case any new overload is added
116
+ // that is supported by `let!`, to ensure the high/low priority
117
+ // overloads still work properly
118
+ taskSeq {
119
+ let! a = task { // eq 1
120
+ do ! Task.Delay 10
121
+ do value <- value + 1
122
+ return value
123
+ }
124
+
125
+ let! b = // eq 2
126
+ task {
127
+ do ! Task.Delay 50
128
+ do value <- value + 1
129
+ return value
130
+ }
131
+ |> ValueTask< int>
132
+
133
+ let! c = ValueTask<_>( 4 ) // valuetask that completes immediately
134
+ let! _ = Task.Factory.StartNew( fun () -> value <- value + 1 ) // non-generic Task with side effect
135
+ let! d = Task.fromResult ( 4 ) // normal Task that completes immediately
136
+ let! _ = Async.Sleep 0 // unit Async
137
+
138
+ let! e = async {
139
+ do ! Async.Sleep 40
140
+ do value <- value + 1
141
+ return value
142
+ }
143
+
144
+ yield ! [ a; b; c; d; e ]
145
+ }
146
+ |> TaskSeq.toListAsync
147
+ |> Task.map ( fun x -> should equal [ 1 ; 2 ; 4 ; 4 ; 3 ])
You can’t perform that action at this time.
0 commit comments