@@ -5,13 +5,14 @@ import Prelude
55import Control.Alt ((<|>))
66import Control.Apply ((*>))
77import 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 )
99import Control.Monad.Aff.AVar (AVAR , makeVar , makeVar' , putVar , modifyVar , takeVar , killVar )
1010import Control.Monad.Aff.Console (log )
1111import Control.Monad.Cont.Class (callCC )
1212import Control.Monad.Eff (Eff )
1313import 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 )
1516import Control.Monad.Error.Class (throwError )
1617import Control.Monad.Rec.Class (tailRecM )
1718import Data.Either (Either (..), either , fromLeft , fromRight )
@@ -137,6 +138,18 @@ test_cancelLater = do
137138 v <- cancel c (error " Cause" )
138139 log (if v then " Success: Canceled later" else " Failure: Did not cancel later" )
139140
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+
140153test_cancelParallel :: TestAVar Unit
141154test_cancelParallel = do
142155 c <- forkAff <<< runParallel $ parallel (later' 100 $ log " Failure: #1 should not get through" ) <|>
@@ -187,69 +200,76 @@ delay n = callCC \cont ->
187200 later' n (cont unit)
188201
189202main :: 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
193213
194- log " Testing pure"
195- test_pure
214+ log " Testing pure"
215+ test_pure
196216
197- log " Testing makeAff"
198- test_makeAff
217+ log " Testing makeAff"
218+ test_makeAff
199219
200- log " Testing attempt"
201- test_attempt
220+ log " Testing attempt"
221+ test_attempt
202222
203- log " Testing later"
204- later $ log " Success: It happened later"
223+ log " Testing later"
224+ later $ log " Success: It happened later"
205225
206- log " Testing kill of later"
207- test_cancelLater
226+ log " Testing kill of later"
227+ test_cancelLater
208228
209- log " Testing kill of first forked"
210- test_killFirstForked
229+ log " Testing kill of first forked"
230+ test_killFirstForked
211231
212- log " Testing apathize"
213- test_apathize
232+ log " Testing apathize"
233+ test_apathize
214234
215- log " Testing semigroup canceler"
216- test_semigroupCanceler
235+ log " Testing semigroup canceler"
236+ test_semigroupCanceler
217237
218- log " Testing AVar - putVar, takeVar"
219- test_putTakeVar
238+ log " Testing AVar - putVar, takeVar"
239+ test_putTakeVar
220240
221- log " Testing AVar killVar"
222- test_killVar
241+ log " Testing AVar killVar"
242+ test_killVar
223243
224- log " Testing finally"
225- test_finally
244+ log " Testing finally"
245+ test_finally
226246
227- log " Test Parallel (*>)"
228- test_parError
247+ log " Test Parallel (*>)"
248+ test_parError
229249
230- log " Testing Parallel (<|>)"
231- test_parRace
250+ log " Testing Parallel (<|>)"
251+ test_parRace
232252
233- log " Testing Parallel (<|>) - kill one"
234- test_parRaceKill1
253+ log " Testing Parallel (<|>) - kill one"
254+ test_parRaceKill1
235255
236- log " Testing Parallel (<|>) - kill two"
237- test_parRaceKill2
256+ log " Testing Parallel (<|>) - kill two"
257+ test_parRaceKill2
238258
239- log " Testing cancel of Parallel (<|>)"
240- test_cancelParallel
259+ log " Testing cancel of Parallel (<|>)"
260+ test_cancelParallel
241261
242- log " Testing synchronous tailRecM"
243- test_syncTailRecM
262+ log " Testing synchronous tailRecM"
263+ test_syncTailRecM
244264
245- log " pre-delay"
246- delay 1000
247- log " post-delay"
265+ log " pre-delay"
266+ delay 1000
267+ log " post-delay"
248268
249- loopAndBounce 1000000
269+ loopAndBounce 1000000
250270
251- all 100000
271+ all 100000
252272
253- cancelAll 100000
273+ cancelAll 100000
254274
255- log " Done testing"
275+ log " Done testing"
0 commit comments