module Test.Main
( main
) where
import Prelude
import Control.Monad.Fork.Class (BracketCondition(..), bracket, fork, uninterruptible)
import Data.Time.Duration (Milliseconds(..))
import Debug.Trace (traceM)
import Effect (Effect)
import Effect.Aff (delay, killFiber, launchAff_)
import Effect.Class (liftEffect)
import Effect.Class.Console as Console
import Effect.Exception (error)
atomic action postAction =
bracket (pure unit) (\a b ->
case a of
Completed x ->
postAction
Failed e ->
traceM "failed"
Killed e ->
traceM "killed"
) (\_-> action)
main :: Effect Unit
main = do
launchAff_ do
fiber <- fork do
atomic
(uninterruptible do
delay $ 15.0 # Milliseconds
liftEffect $ Console.log "hi"
)
(liftEffect $ Console.log "here")
delay $ 10.0 # Milliseconds
killFiber (error "asdf") fiber
The above code only traces "killed", although it should most likely have run the postAction handler, thus printing "here" to the console.
The above code only traces "killed", although it should most likely have run the
postActionhandler, thus printing "here" to the console.