@@ -5,13 +5,14 @@ import Prelude
5
5
import Control.Alt ((<|>))
6
6
import Control.Apply ((*>))
7
7
import Control.Parallel.Class (parallel , runParallel )
8
- import Control.Monad.Aff (Aff , runAff , makeAff , later , later' , forkAff , forkAll , Canceler (..), cancel , attempt , finally , apathize )
8
+ import Control.Monad.Aff (Aff , runAff , makeAff , launchAff , later , later' , forkAff , forkAll , Canceler (..), cancel , attempt , finally , apathize )
9
9
import Control.Monad.Aff.AVar (AVAR , makeVar , makeVar' , putVar , modifyVar , takeVar , killVar )
10
10
import Control.Monad.Aff.Console (log )
11
11
import Control.Monad.Cont.Class (callCC )
12
12
import Control.Monad.Eff (Eff )
13
13
import Control.Monad.Eff.Console (CONSOLE )
14
- import Control.Monad.Eff.Exception (EXCEPTION , throwException , error , message )
14
+ import Control.Monad.Eff.Console (log ) as Eff
15
+ import Control.Monad.Eff.Exception (EXCEPTION , throwException , error , message , try )
15
16
import Control.Monad.Error.Class (throwError )
16
17
import Control.Monad.Rec.Class (tailRecM )
17
18
import Data.Either (Either (..), either , fromLeft , fromRight )
@@ -137,6 +138,18 @@ test_cancelLater = do
137
138
v <- cancel c (error " Cause" )
138
139
log (if v then " Success: Canceled later" else " Failure: Did not cancel later" )
139
140
141
+ test_cancelLaunchLater :: forall e . Eff (console :: CONSOLE , err :: EXCEPTION | e ) Unit
142
+ test_cancelLaunchLater = do
143
+ c <- launchAff $ later' 100 $ log (" Failure: Later was not canceled!" )
144
+ void $ launchAff $ (do v <- cancel c (error " Cause" )
145
+ log (if v then " Success: Canceled later" else " Failure: Did not cancel later" ))
146
+
147
+ test_cancelRunLater :: forall e . Eff (console :: CONSOLE | e ) Unit
148
+ test_cancelRunLater = do
149
+ c <- runAff (const (pure unit)) (const (pure unit)) $ later' 100 $ log (" Failure: Later was not canceled!" )
150
+ void $ try $ launchAff $ (do v <- cancel c (error " Cause" )
151
+ log (if v then " Success: Canceled later" else " Failure: Did not cancel later" ))
152
+
140
153
test_cancelParallel :: TestAVar Unit
141
154
test_cancelParallel = do
142
155
c <- forkAff <<< runParallel $ parallel (later' 100 $ log " Failure: #1 should not get through" ) <|>
@@ -187,69 +200,76 @@ delay n = callCC \cont ->
187
200
later' n (cont unit)
188
201
189
202
main :: Eff (console :: CONSOLE , avar :: AVAR , err :: EXCEPTION ) Unit
190
- main = runAff throwException (const (pure unit)) $ do
191
- log " Testing sequencing"
192
- test_sequencing 3
203
+ main = do
204
+ Eff .log " Testing kill of later launched in separate Aff"
205
+ test_cancelLaunchLater
206
+
207
+ Eff .log " Testing kill of later run in separate Aff"
208
+ test_cancelRunLater
209
+
210
+ void $ runAff throwException (const (pure unit)) $ do
211
+ log " Testing sequencing"
212
+ test_sequencing 3
193
213
194
- log " Testing pure"
195
- test_pure
214
+ log " Testing pure"
215
+ test_pure
196
216
197
- log " Testing makeAff"
198
- test_makeAff
217
+ log " Testing makeAff"
218
+ test_makeAff
199
219
200
- log " Testing attempt"
201
- test_attempt
220
+ log " Testing attempt"
221
+ test_attempt
202
222
203
- log " Testing later"
204
- later $ log " Success: It happened later"
223
+ log " Testing later"
224
+ later $ log " Success: It happened later"
205
225
206
- log " Testing kill of later"
207
- test_cancelLater
226
+ log " Testing kill of later"
227
+ test_cancelLater
208
228
209
- log " Testing kill of first forked"
210
- test_killFirstForked
229
+ log " Testing kill of first forked"
230
+ test_killFirstForked
211
231
212
- log " Testing apathize"
213
- test_apathize
232
+ log " Testing apathize"
233
+ test_apathize
214
234
215
- log " Testing semigroup canceler"
216
- test_semigroupCanceler
235
+ log " Testing semigroup canceler"
236
+ test_semigroupCanceler
217
237
218
- log " Testing AVar - putVar, takeVar"
219
- test_putTakeVar
238
+ log " Testing AVar - putVar, takeVar"
239
+ test_putTakeVar
220
240
221
- log " Testing AVar killVar"
222
- test_killVar
241
+ log " Testing AVar killVar"
242
+ test_killVar
223
243
224
- log " Testing finally"
225
- test_finally
244
+ log " Testing finally"
245
+ test_finally
226
246
227
- log " Test Parallel (*>)"
228
- test_parError
247
+ log " Test Parallel (*>)"
248
+ test_parError
229
249
230
- log " Testing Parallel (<|>)"
231
- test_parRace
250
+ log " Testing Parallel (<|>)"
251
+ test_parRace
232
252
233
- log " Testing Parallel (<|>) - kill one"
234
- test_parRaceKill1
253
+ log " Testing Parallel (<|>) - kill one"
254
+ test_parRaceKill1
235
255
236
- log " Testing Parallel (<|>) - kill two"
237
- test_parRaceKill2
256
+ log " Testing Parallel (<|>) - kill two"
257
+ test_parRaceKill2
238
258
239
- log " Testing cancel of Parallel (<|>)"
240
- test_cancelParallel
259
+ log " Testing cancel of Parallel (<|>)"
260
+ test_cancelParallel
241
261
242
- log " Testing synchronous tailRecM"
243
- test_syncTailRecM
262
+ log " Testing synchronous tailRecM"
263
+ test_syncTailRecM
244
264
245
- log " pre-delay"
246
- delay 1000
247
- log " post-delay"
265
+ log " pre-delay"
266
+ delay 1000
267
+ log " post-delay"
248
268
249
- loopAndBounce 1000000
269
+ loopAndBounce 1000000
250
270
251
- all 100000
271
+ all 100000
252
272
253
- cancelAll 100000
273
+ cancelAll 100000
254
274
255
- log " Done testing"
275
+ log " Done testing"
0 commit comments